race-condition

Is the != check thread safe?

倾然丶 夕夏残阳落幕 提交于 2019-12-04 07:39:59
问题 I know that compound operations such as i++ are not thread safe as they involve multiple operations. But is checking the reference with itself a thread safe operation? a != a //is this thread-safe I tried to program this and use multiple threads but it didn't fail. I guess I could not simulate race on my machine. EDIT: public class TestThreadSafety { private Object a = new Object(); public static void main(String[] args) { final TestThreadSafety instance = new TestThreadSafety(); Thread

Get or create child Akka actor and ensure liveness

孤街浪徒 提交于 2019-12-04 07:17:16
I am trying to use a hierarchy of Akka actors to handle per user state. There is a parent actor that owns all the children, and handles the get-or-create in the correct way (see a1 , a2 ): class UserActorRegistry extends Actor { override def Receive = { case msg@ DoPerUserWork(userId, _) => val perUserActor = getOrCreateUserActor(userId) // perUserActor is live now, but will it receive "msg"? perUserActor.forward(msg) } def getOrCreateUserActor(userId: UserId): ActorRef = { val childName = userId.toActorName context.child(childName) match { case Some(child) => child case None => context

Signal handler accessing queue data structure (race condition?)

青春壹個敷衍的年華 提交于 2019-12-04 06:48:04
I'm currently writing a small shell in C++. Jobs and the PIDs associated with them are stored within a queue of job pointers (job *) . When a new job is run, information about it is added to the queue. Since multiple jobs can be handled simultaneously and new jobs can be entered at the shell's console at any time, I have a signal handler to wait on jobs which are terminated. When a job is terminated, I need to remove it's information from the active job queue and move it to my deque of terminated jobs. However, it is possible that a user's new job is being added to the queue when another job

ReactJS concurrent SetState race condition

我的未来我决定 提交于 2019-12-04 05:50:22
I have a component structure like this <A> <B> <C/> <C/> </B> <D> <E/> <E/> </D> </A> Idea is that actions on components in block E are processed by a function of component A to state of A and than passed down to B and C as props. I know, that better way was to use Flux, pubsub-js or other Store-message system, but hope if someone can explain why correct to the best of my understanding solution doesn't work. Calling this function of component A simalteneously from multiple instances of component E leads to race condition with only one change in state (instead of each function call providing a

downloading from AWS S3 while file is being updated

拥有回忆 提交于 2019-12-04 04:18:37
This may seem like a really basic question, but if I am downloading a file from S3 while it is being updated by another process, do I have to worry about getting an incomplete file? Example: a 200MB CSV file. User A starts to update the file with 200MB of new content at 1Mbps. 16 seconds later, User B starts download the file at 200Mbps. Does User B get all 200MB of the original file, or does User B get ~2MB of User A's changes and nothing else? User B gets all 200MB of the original file. Here's why: PUT operations on S3 are atomic. There's technically no such thing as "modifying" an object.

Race conditions “check-then-act” and “read-modify-write”

ε祈祈猫儿з 提交于 2019-12-03 18:06:08
问题 Anyone can explain me about what is race condition, how to avoid it, and how to find it out in java codes? Okay, I just know "race condition" several days, I have two examples, maybe they are not good enough, that's why I need your help:) Hope any of you can explain it for me. example1: check then act: if(vector.contains(e))//check { vector.remove(e) } if there are 2 threads can access, thread1 suspends after check vector contains e, and e does in vector, then thread2 access to check and then

Is Thread Sanitizer usable?

不问归期 提交于 2019-12-03 16:33:18
I thought of trying out thread sanitizer ( http://code.google.com/p/data-race-test/wiki/ThreadSanitizer#Using_ThreadSanitizer ) so I made a simple program: #include <thread> #include <atomic> #include <vector> #include <iostream> #include <algorithm> #include <mutex> using namespace std; int violated=0; mutex mtx; void violator() { lock_guard<mutex> lg(mtx); violated++; } int main() { thread t1(violator); t1.join(); thread t2(violator); t2.join(); } AFAIK program is OK since access to violated is synced with mutex(and like comments say even without that program is race free). But tsan

Strange behavior of a Java thread associated with System.out [duplicate]

断了今生、忘了曾经 提交于 2019-12-03 16:04:08
This question already has an answer here : Closed 4 years ago . Loop doesn't see value changed by other thread without a print statement (1 answer) I have a simple TestThreadClientMode class to test a race condition. I tried two attempts: When I run the following code with System.out.println(count); commented in the second thread, the output was: OS: Windows 8.1 flag done set true ... and the second thread was alive forever. Because the second thread never sees change of the done flag which was set true by Main thread. When I uncommented System.out.println(count); the output was: OS: Windows 8

[APUE]Does parent and child share the same file offset after fork?

一世执手 提交于 2019-12-03 15:31:45
In APUE section 8.3 fork function , about file sharing between parent and child processes, It said: It is important that the parent and the child share the same file offset. And in section 8.9 Race Conditions , there is a example: both parent and child write to a file which is opened before invoking fork function. The program contains a race condition, because the output depends on the order in which the processes are run by the kernel and for how long each process runs. But in my test code, the output are overlapped. [Langzi@Freedom apue]$ cat race.out this is a long long outputhis is a long

Terrible performance - a simple issue of overhead, or is there a program flaw?

↘锁芯ラ 提交于 2019-12-03 15:28:55
I have here what I understand to be a relatively simple OpenMP construct. The issue is that the program runs about 100-300x faster with 1 thread when compared to 2 threads. 87% of the program is spent in gomp_send_wait() and another 9.5% in gomp_send_post . The program gives correct results, but I wonder if there is a flaw in the code that is causing some resource conflict, or if it is simply that the overhead of the thread creation is drastically not worth it for a a loop of chunk size 4. p ranges from 17 to 1000, depending on the size of the molecule we're simulating. My numbers are for the