Questions tagged [thread-synchronization]

In a multi-threaded environment thread synchronization is used to coordinate access to shared resources such as file handles, network connections, and memory

In a multi-threaded environment thread synchronization is used to coordinate access to shared resources such as file handles, network connections, and memory

References

645 questions
0
votes
2 answers

Java Multi Threading synchronized block Looping forever

I implemented sample program to make sure that not more than 5 thread execute a particular process at a time. But the result is not as expected. public class MiscUtils{ private volatile static int count = 0; public synchronized static int…
0
votes
1 answer

In a SPSC framework condition_variable.notify_one() is not signalling consistently

The producer, after each push into the queue, signals the consumer via conditionVar.notify_one(). However, the consumer wakes up after some random number of pushes (hence the subsequent notify_one()s) take place, sometimes 21 sometimes 2198,…
0
votes
1 answer

What will happen if you modify the reader process in reader-writer problem?

Here is the code for the reader process (workable code) reader(){ while(true){ P(mutex); readerCounter++; if((readerCount == 1) P(OKtoaccessDB); V(mutex); accessDB; readerCounter--; if(readerCounter == 0) …
0
votes
0 answers

Efficient Timeout for a blocking operation without synchronization

I'm trying to create a timeout for a blocking operation, a InputStream.read() in the specific case, using a timeout thread without synchronization. This is needed to avoid that a blocking operation will last forever and its aim is to achieve the…
Michele Mariotti
  • 7,372
  • 5
  • 41
  • 73
0
votes
0 answers

multiple array iteration in multiple threads to add

I have a simple Computer class with 3 fields and Computers class which has Computer[] array and sortedAdd method, which adds elements to internal array in a sorted manner. In main method I have computers array which has all records from the files…
0
votes
1 answer

Does a timer runs on a different thread in Reactjs

I got a Reactjs code of a class, which saves an array of data per instance. There is a method like addData(data) which just pushes the new data to the array. I have also got a call to setInterval with an action which is supposed to use the data…
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
0
votes
1 answer

OpenMP - Run single region with nowait and after join other threads in for loop

What I'm trying to do is that the first part of the function runs in a single thread and other thread start the second function (this function has three loops) and after the single thread ends the first function he join with others to help with…
Guus
  • 15
  • 3
0
votes
1 answer

Deadlock Prevention, random thread execution order C

I am building a program for a school assignment. It has the following requirements as shown below. Must use Mutexes Must use Pthreads Create 5 threads with random synchronization (aka: running in a non-specific order) Threads must be detached from…
Felauras
  • 71
  • 9
0
votes
1 answer

Can I make threads wait for a lock and then jump over it once released?

Given is the following pseudo code. A function may be entered by multiple threads simultaneously. I want all threads to execute a() and c(), but b() must only be executed by those threads that were not locked when entering the synchronized block. In…
0
votes
1 answer

How can I implement a single-writer, multiple-reader queue with pthreads?

I am trying to implement a single-writer, multiple-reader queue in pthreads. The synchronization pattern works but eventuallly deadlocks after repeated requests (I believe). It works with one writer boss thread and one reader worker thread…
Anthony O
  • 622
  • 7
  • 26
0
votes
2 answers

Multiple read writes on a single static integer index causes index to go out of bounds

I was trying to learn multi threading, and was trying out a simple producer/consumer pattern with wait and notify. When i split the pattern with two consume and one produce i get an ArrayIndexOutOfBounds Exception which is not clear. The issue does…
Shravi
  • 29
  • 11
0
votes
2 answers

How to distinguish threads that have locked to different instances?

I learned that threads can lock onto "the resources", let's say an object, they're using so that only one at a time is allowed to use and modify it which is the problem of synchronization. I created two different instances of one class and fed it to…
cutus_low
  • 85
  • 5
0
votes
1 answer

Can I force a step in my dataflow pipeline to be single-threaded (and on a single machine)?

I have a pipeline that takes URLs for files and downloads these generating BigQuery table rows for each line apart from the header. To avoid duplicate downloads, I want to check URLs against a table of previously downloaded ones and only go ahead…
0
votes
1 answer

Wait for a deferred value in a lambda before returning it in a function

I have a function call (in a SignalR hub) that is supposed to return a MyState object. The MyState object is not quite ready at the time it is needed by the caller and has to be processed first by some background process prior being eligible as…
Larry
  • 17,605
  • 9
  • 77
  • 106
0
votes
1 answer

How to explain thread synchronization mechanism at OS level conceptually?

There is lot of discussion on thread synchronization on SO as well as on many forums all-over the Internet. However, I could not find precise information as to how exactly it happens at OS level conceptually. As we all know there are these types of…
Atul
  • 3,778
  • 5
  • 47
  • 87