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
1 answer

How to print the live data from ProcessBuilder to console in Java?

Below is my code to read the output from console. I need to read the tracert path live to console. Below code prints the data at once after finishing the process only. Can someone help me? ProcessBuilder f = new ProcessBuilder("cmd.exe","tracert…
0
votes
0 answers

Multithreading and up-to-date check

Does the following require some kind of synchronization? Control Worker 1 Worker 2 ... Worker n Test if all a_n is true. If so, dispatch a new job. Otherwise, try again. when done: set a_1 to true when done: set a_2 to true ... when done:…
user877329
  • 6,717
  • 8
  • 46
  • 88
0
votes
1 answer

Why use Volatile.Write in Double-Check Locking?

Below is some code from a C# book to show how Singleton pattern is constructed in multithreading: internal sealed class Singleton { // s_lock is required for thread safety and having this object assumes that creating // the singleton object is…
user16276760
0
votes
0 answers

Task running order when using SemaphoreSlim

I'm trying to understand some basic multitasking approaches and concepts like Thread/Task/Semaphore. I'm a bit confused about semaphore and it's waiting mechanism. I have created an example program. Fiddle What I want to do is executing BigLock()…
tzairos
  • 35
  • 2
  • 8
0
votes
2 answers

Correctly synchronizing/locking access to an ArrayList

I am working on my first Spring-Boot application, after not touching Java in ages. Below is one of my classes. import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVRecord; import…
0
votes
1 answer

C - Thread stuck indefinitely while waiting

I'm having trouble with implementing the "dining philosopher" problem. Basically my program is stuck in an infinite loop while threads are waiting. I'am trying to implement it in a way so that it enforces the order of eating. so Philosopher 0 would…
anthony
  • 71
  • 4
0
votes
1 answer

PowerShell CloseHandle on EventWaitHandle

I have two PowerShell scripts. One of them has to wait at the other at one point. Here are the relevant parts: WaitingScript.ps1: $StopEventName = 'MyEvent' function Wait-StopEvent { $EventResetModeManualReset = 1 $StopEventObject =…
0
votes
1 answer

C# Backgroundworker threadsafety

I have another question about threadsaftey according to memory access. What about the synchronisation of objects passed to BackgroundWorker RunWorkerAsync(object) and returning to Result? Lets say we have class (simplified) We assume that threads…
MrV
  • 25
  • 5
0
votes
2 answers

Why does my code enter a locked area if the previous code has not released the lock?

My project has a button. When the button is pushed, it executes a function, SimulateDataUpload. This SimulateDataUpload is locked with lock.lock(). There is a for loop, packaged in a runnable, which updates a progress bar. The onRun of the runnable…
Tim
  • 478
  • 4
  • 15
0
votes
1 answer

producer consumer problem c no output for consumer

here im trying to, use a circular queish thing for my insert and remove methods, as well as use the insert and remove functions for synchronization im compiling with gcc file.c -lpthread -lrt and running with ./a.out 50 1 1. upon running my producer…
Bell
  • 29
  • 5
0
votes
2 answers

How can you check when a Java 8 Stream.forEach() finishes iterating?

I want to use the parallelism that Java 8 Streams provide, but I also need certain operations to be done in a specific order or else everything will break. The problem is that using a stream means that the code is now asynchronous [NOTE: THIS IS…
0
votes
0 answers

how to synchronize threads using Lock object

in the below code i am learning how to synchronize threads. i referred to several tutorials. as stated in the tutorials, i must use Lock() object so to call .acquire() and .release() I coded the below code but i always receive the following…
Amrmsmb
  • 1
  • 27
  • 104
  • 226
0
votes
1 answer

Thread-safe locking/sychronizing to one permit per resource with multiple resources

I need to implement thread-safe synchronization to multiple resources, where each resource can be accessed by one thread at a time, but different resources can be accessed concurrently. I have come up with the following code, meant to be used in a…
0
votes
1 answer

Can a thread lose control after calling a method but before the first instruction of the method?

I need to record the exact order in which a method is called by various threads in Java. I'm supposed to use an object timeProvider which returns non-decreasing long integers. The solution I have come up with is: public synchronized void method() { …
kade99
  • 37
  • 6
0
votes
0 answers

How to deal with timed out semaphore wait

I have two threads being synchronized with semaphores. Thread1 is waiting for a sem_post() by Thread2 using sem_timedwait(). But I fear that whenever timeout happens, the corresponding sem_post() which may happen at a later time, will increment the…