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
3 answers

Why does the below code increment value with 2 rather than 1?(New to Java)

In the below code after a thread runs the increment method it prints value 2 to the console.Shouldn't the value be 1 since the method increments it with 1? class TestSync implements Runnable { private int balance; public void run() { …
0
votes
1 answer

How to Synchronizing / Locking a Variable right?

I have a problem understanding synchronized(){} in Java. Somehow I thought that synchronized(this) I locking THIS instance of the Class and if I wanna access an attribute OR calling a function of this particular instance from another thread, than…
0
votes
1 answer

ReentrantLock tryLock()

This is the source code of ReentrantLock#tryLock: public boolean tryLock() { return sync.nonfairTryAcquire(1); } My question is that: There are two types of Synchronizers: FairSync and NonFairSync in the ReentrantLock. Why only the…
jimwi
  • 33
  • 3
0
votes
1 answer

Synchronize two functions into separate classes

In a class there are different functions. In a separate file in another class I want to catch the messages and print to gui. As a simulation I have the following code: import threading import time import…
0
votes
1 answer

Updating GUI through threads

I'm fairly new to threads and haven't written Java in a long time so bear with me here. I have a very simple GUI. It has a counter, a status label, and two buttons, start and stop respectively. What I wanted it to do was update my status label using…
0
votes
1 answer

Can I do random writes from a kernel without worrying about synchronization issues?

Consider a simple depth-of-field filter (my actual use case is similar). It loops over the image and scatters every pixel over a circular neighborhood of its. The radius of the neighborhood depends on the depth of the pixel - the closer the it is to…
Stefan Monov
  • 11,332
  • 10
  • 63
  • 120
0
votes
2 answers

TBB spin_mutex inside parallel_for to block a critical section

Conceptually, how can I block a critical section inside a tbb::parallel_for call using tbb:spin_mutex? The critical section is less than 20 instructions so spin_mutex is ideal. For example the following dummy code explains the situation: function()…
0
votes
1 answer

Java Threads | Producer Consumer : What's wrong with the code?

Trying to learn multithreading and inter-process communication of threads. Have implemented a typical producer-consumer problem. However, the output am getting is pretty sequential which should not be the case while working with threads ideally. Ok,…
roger_that
  • 9,493
  • 18
  • 66
  • 102
0
votes
1 answer

Choosing right object for locking in thread synchronization?

Generally code samples use locks this way: static readonly object lockForWorkingWithSharedObject = new object(); lock(lockForWorkingWithSharedObject) { // do something with shared object } This way we need many locks in a large class. Is it…
Xaqron
  • 29,931
  • 42
  • 140
  • 205
0
votes
1 answer

State of a signaled thread in Java when calling condition.signal()

I am looking for the answer to the following question. Suppose we have two threads in Java. We synchronize them by using Lock and Condition classes on the same object of Lock: Thread A calls: condition.await(); Thread B does some work and then…
0
votes
1 answer

TQueue gets never emptied if Dequeue used as a procedure parameter

interface type TMulticastListenerThread = class(TThread) strict private ..... _queue: TQueue; FOnReceive: TGetStrProc; procedure DoReceive(); ..... public ..... procedure Execute(); override; property OnReceive:TGetStrProc…
Paul
  • 25,812
  • 38
  • 124
  • 247
0
votes
1 answer

thread synchronization between c# and c++

I have a C# WPF app that needs to call an unmanaged C++ DLL and get a simple event notification from it. The DLL will wait for a keyboard event that can't be seen in .NET (VK_MEDIA_PLAY_PAUSE while the app doesn't have the input focus), and notify…
Gregor J
  • 31
  • 7
0
votes
2 answers

How to assign different threads to different methods of other class not using main main thread

Lets say I have a main class Start.java public class Start{ //Here I want to integrate the programs for which i will be needing threads } and I also have two more classes which contains two different methods. public class ReadUpdateDb { …
0
votes
1 answer

Thread safety in google endpoints and Objectify and how does allocateId works ?

I have an OfyService class of this type /** * Custom Objectify Service that this application should use. */ public class OfyService { /** * This static block ensure the entity registration. */ static { …
0
votes
1 answer

One-time wake a waiting thread in Python

I have a Python object that is updated regularly, from an asynchronous I/O callback. A few threads need to wait for this object to be updated. This "update" event is an instantaneous event, and as well the action of telling the waiting threads to…