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

Readers-Writers problem writers-preference (readers may starve)

I have problem with readers-writers problem. I want to write writers favor solution using mutex. So far i have written this #include #include #include #include #include #include…
0
votes
0 answers

Question in Synchronization when two requests comes

I’m asked these two interview questions in my interview and nowhere in web I could get the answer, as I’m sort of new to programming. Can someone please help me with some Answers for these. How to attain synchronisation or concurrency…
Jasmine
  • 5,186
  • 16
  • 62
  • 114
0
votes
1 answer

Java: Synchronize two scheduled threads on ScheduledExecutorService

I want to create a program that: Does a long running task, lets say ChildJob Pauses the main task ChildJob, and commits the work done every few seconds I came up with this code that schedules two threads, will commit every few seconds (commit part…
0
votes
0 answers

Two mutexes with condition variable to lock one class, threads

I'm trying to solve a dinning philosophers problem using chandy-misra algorithm. More explanation here: https://en.wikipedia.org/wiki/Dining_philosophers_problem I'm using one mutex to lock the modified variables and another with condition variable…
0
votes
0 answers

Should I use critical section or syncronize/queue to modify class data members?

Let's say TForm1 class (default main window) contains data member int x;. If I create additional threads from TThread descendant should I use critical section object or Synchronize/Queue methods to modify value of x inside thread's Execute method?…
Tracer
  • 2,544
  • 2
  • 23
  • 58
0
votes
0 answers

Cannot synchronize std::thread via std::vector

Code I've got an algorithm to run using threads. When several parts of the algorithm are coming to a specific step, I want the main thread to know this. I work under Xubuntu 18.04. Code of the main application follows this scheme vector
0
votes
1 answer

check asynchronous threads state in java

I have method in class MyClassB which is triggered asynchronously from a method of MyClassA: public void getProductCall() { new Thread(new Runnable() { @Override public void run() { try { …
0
votes
1 answer

Two Process Solution for Critical Section Problem- Algorithm 1

I have started learning Critical Section Problem and its various solutions. To explain my question, let me first give a brief background of it. The general structure for a two Process Solution for Critical Section Problem- Algorithm 1 is: turn =…
0
votes
1 answer

Synchonizing on Java Class instance to store and retrieve Dynamically created Proxy classes at runtime

In our web application exists 'Access Bean' classes with some methods on them which perform queries on a DB, these are invoked multiple times per request. Therefore they need to be cached but the original classes cannot be altered as they are from…
0
votes
1 answer

Thread scheduling and synchronization

Is it possible for the thread scheduler to unschedule a thread holding the lock to a synchronized block and is in the middle of executing it? If yes then does the unscheduling leads to thread releasing the lock? Assume thread doesn't call method…
0
votes
3 answers

When should a method be declared synchronized?

Following is a, simple, working program which uses two threads to print a counter: public class SynchronizedCounter implements Runnable { private static int i = 0; public void increment() { i++; } public int getValue() { return i; } …
user1418717
  • 425
  • 2
  • 5
  • 13
0
votes
0 answers

Thread never acquires shared lock

I was learning about the old-school Java synchronization mechanisms and stumbled upon some problems. Code available on GitHub. Consider the following test example. From the main method, we construct a garage Platform object, represented by a char…
0lt
  • 283
  • 2
  • 13
0
votes
2 answers

Can static variables ever be used to synchronize threads?

Below I have constructed an example which synchronizes three threads based on a static variable: public class CallMethodsInOrder { public static void main(String[] args) { // Three instances of Thread, first calls first, second second…
0
votes
1 answer

Synchronization not working for below simple Java code

I have started learning about multi-threading and synchronization in Java and decided to do some practical. I wrote a simple code wherein I have two synchronized methods whose class object is being shared by three threads, but when I run this code ,…
0
votes
2 answers

Synchronizing child threads to atomic time managed by parent

  I am trying to write a simulation where different threads need to perform a given calculation on a thread-specific interval (in the minimal example here that interval is between 1 and 4) based on an atomic simulation time managed by a parent…