concurrency

Are BSD/Posix sockets reentrant?

痴心易碎 提交于 2019-12-24 06:23:31
问题 Can several threads operate on the same socket descriptor, i.e accept(sock_fd) at the same time without concern? The platform I'm mostly interested in is POSIX/Linux. 回答1: Yes, they are "reentrant" - kernel locks the socket structure while working on it (see Linux accept source for example), so only one thread would get the client connection. 来源: https://stackoverflow.com/questions/2133224/are-bsd-posix-sockets-reentrant

Atomicity of Reads and Writes for Reference Variables in Java

我们两清 提交于 2019-12-24 05:58:55
问题 First the quote from From JLS 8 Sec 17.7 Writes to and reads of references are always atomic, regardless of whether they are implemented as 32-bit or 64-bit values. Here is the scenario that confuses me, given Employee class and a method within this class called calculate which returns a reference to an instance of Employee. Employee emp = calculate(); When a write to variable is atomic, it means that no other thread can access that variable until the atomic operation is done, and in the

Concurrency scenarios with INSERTs

自闭症网瘾萝莉.ら 提交于 2019-12-24 04:44:05
问题 I'm designing a booking system in PHP + PostgreSQL. I'm not able to find a clean solution to a concurrency problem based on INSERTs operations. The DB system is mainly made of these tables: CREATE TABLE booking ( booking_id INT, user_id INT, state SMALLINT, nb_coupons INT ); CREATE booking_state_history ( booking_state_history_id INT, timestamp TIMESTAMP, booking_id INT, state SMALLINT); CREATE TABLE coupon_purchase( coupon_purchase_id, user_id INT, nb INT, value MONEY) CREATE TABLE coupon

How to catch/detect exceptions in multi-threaded map/reduce using Reactor framework 2.x?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 04:25:09
问题 I was playing with the code of this answer and it works smoothly. However, if an exception is thrown, the caller code does not catch it. How is an Exception captured in reactor 2.0 streams? What I want to do is: if an Exception is thrown, stream processing must stop. I need to throw the Exception up in the caller thread (the one that created the steam in first place). List<Map<String, Object>> data = readData(); Streams.from(data) .flatMap(m -> Streams.just(m) .dispatchOn(Environment

Tools to test/debug/fix PHP concurrency issues?

吃可爱长大的小学妹 提交于 2019-12-24 04:22:09
问题 I find myself doing some relatively advanced stuff with memcached in PHP. It's becoming a mental struggle to think about and resolve race conditions and concurrency issues caused by the lock-free nature of the cache. PHP seems pretty poor in tools when it comes to concurrency (threads, anyone?), so I wonder if there are any solutions out there to test/debug this properly. I don't want to wait until two users request two scripts that will run as parallel processes at the same time and cause a

Confused by docs and source of CountedCompleter

隐身守侯 提交于 2019-12-24 04:09:28
问题 Here is a code fragment of java.util.concurrent.CountedCompleter class (JDK 1.8.0_25). /** * If the pending count is nonzero, decrements the count; * otherwise invokes {@link #onCompletion(CountedCompleter)} * and then similarly tries to complete this task's completer, * if one exists, else marks this task as complete. */ public final void tryComplete() { CountedCompleter<?> a = this, s = a; for (int c;;) { if ((c = a.pending) == 0) { a.onCompletion(s); if ((a = (s = a).completer) == null) {

How to return awaitable (Task?) that waits for an event in Dispatcher Thread

久未见 提交于 2019-12-24 04:09:04
问题 I have threads: UI thread with Dispatcher loop background thread that listens for messages in a queuing framework. when a message is received, an event is fired in the background thread: messageReceiver.Received += (sender, args) => ... In UI thread I would like to await a message, something like this: void ButtonClicked(object sender, RoutedEventArgs e) { await NextMessage(); //should return when messageReceiver.Received is fired } How to implement awaitable NextMessage method, so it does

Can Lost Update happen in read committed isolation level in PostgreSQL?

被刻印的时光 ゝ 提交于 2019-12-24 04:01:31
问题 I have a query like below in PostgreSQL: UPDATE queue SET queue.status = 'PROCESSING' WHERE queue.status = 'WAITING' AND queue.id = (SELECT id FROM queue WHERE STATUS = 'WAITING' LIMIT 1 ) RETURNING queue.id and many workers try to process one work at a time (that's why I have sub-query with limit 1). After this update, each worker grabs information about the id and processes the work, but sometimes they grab the same work and process it twice or more. The isolation level is Read Committed.

How do I flush to Java's JTextArea?

你离开我真会死。 提交于 2019-12-24 03:54:08
问题 I am writing a GUI with a button. When the user clicks the button, I would like a "Beginning work..." message to appear in a JTextArea immediately, and a "Finished." message to appear when the work is done. The GUI contains some code of the form private void buttonActionPerformed(java.awt.event.ActionEvent evt) { myJTextArea.append("Beginning work...\n"); <more lines of code> myJTextArea.append("Finished.\n"); } Unfortunately, neither message appears until the end. Is there a way to flush

JDialog misbehaviour

爷,独闯天下 提交于 2019-12-24 03:25:22
问题 JDialog dialog = new JDialog(parent JFrame, "blabla"); dialog.setLayout(new BorderLayout()); JLabel label = new JLabel("more blabla"); dialog.getContentPane().add(label, BorderLayout.CENTER); dialog.setSize(new Dimension(280, 80)); dialog.setLocationRelativeTo(parent JFrame); dialog.setVisible(true); //part of code that takes time to execute //actually, I'm sending an email here, but it doesn't really matter what I do, //as you will read below dialog.dispose(); I have the code above and it's