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 can i Implement synchronized in Java?

i have an Assignment about Multithreading and i need some help. I have a Ressource class which cannot be changed public class Ressource { public int val; public void incr() { val++; } public void decr() { val--; …
user10751443
0
votes
1 answer

sleep() and context switching in java threads

Lets assume a situation like this : Lets say Thread0 access the lockObject first and then Thread0 going to sleep for 1000ms. synchronized(lockObject) { Thread0.sleep(1000); } Thread1 also waiting for access the lockObject. What happened in…
0
votes
0 answers

I need help fixing a part of this code, i tried to make a message after another message in multiplethreads java, but its not working, what can i do?

this is on a class apart from other, the goal is that the passangers go from the airport to A and then to B and then back to the airport, but when the passangers want to go back to the airport from B, most times it appears that they arrived at the…
0
votes
1 answer

Java Thread Synchronization 101

Thinking that the shared object Control would enforce that n threads (Number) display in order, they clearly do not: Number: public class Number implements Runnable { private int i_; private Control control; public Number(int i,…
0
votes
1 answer

Program with multiple threads always giving same output

I'm learning multi-threading and trying to create a program that can print two strings alternately. I have written the following code : #include #include #include #include pthread_mutex_t lock; void print(char…
0
votes
0 answers

Are these three kinds of synchronization equivalent?

This: private final Object lock = new Object(); public void doSomething() { synchronized (lock) { // do something } } vs. this: public void doSomething() { synchronized (this) { // do something } } vs. this: public…
tom
  • 2,137
  • 2
  • 27
  • 51
0
votes
0 answers

Trouble running multiple threads using ThreadPool and pool.map(func, list_on_which_will_func_will_be_applied) in python 3.8

I'm trying to read a 400 MB text file and I'm reading it in chunks as I need to extract the words from it and I'm trying to use thread pool but it running longer than I ran as a single process. Below are the two functions, def process_text(self): #…
0
votes
1 answer

Why else condition not shows over console for waiting Thread. if i'm using future.get() method?

Here in office instance getsum() returns sum of n number digits and only one Thread allowed to complete the calculation at a time with a sleep of 1 seconds. During this time other Thread will try for lock, If Thread not get lock it prints else…
0
votes
1 answer

Is Entrance into a Windows Critical Section an atomic operation?

I wrote an FFI for critical sections, and I wrote a test for it in Haxe. Tests run in order defined (public functions are tests) This test test_critical_section will intermittently hang and fail: 1 var criticalSection:CriticalSection; 2 3 #if…
0
votes
0 answers

SaveChangesAsync() getting stuck

I have problem and i think its a deadlock and i cant resolve the problem. I know there simular problem discuse but i need help. When i try to saveChange on productReposotory it stuck and dont execute the other code. Here is my controller: public…
0
votes
1 answer

How to synchronize a method call between tasks in net core 3

In my application I have a BackgroundService which also includes the following method: GetNumberAsync() gets the "oldest" record from database and updates the properties of the record. This method is called from API controller async method…
0
votes
1 answer

Number of threads waiting on a condition variable

I like to know that is there a way to know the number of threads waiting on a condition variable from the condition variable itself, without using some "count" variable?
0
votes
1 answer

Does a thread in 'ready' state acquire a lock

Threads and parallel programming is really confusing the heck outta me. In this book, at page 9, the problem stated is that though a thread might be scheduled and put in the ready state, it does not necessarily mean that it has acquird a lock.…
0
votes
1 answer

C++ threads: How to stop one thread from executing while other is still running (Win32)

The problem persists on Win32 environment in Visual Studio. I have 2 classes: void classA::DoSth(HWND param){ for(int i = 0; i<24; i++) std::cout<
0
votes
1 answer

Multithreading drawing using BufferedImage

I have a school assignment where I have to multiple threads drawing rectangles over an image. Shapes in progress cannot overlap (ie two threads cannot be simultaneously trying to draw in the same region) I have to do this using get/setRGB but I'm…