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

Consumer Producer- Producer thread never executes assigned function

I have .NET Core Web API solution. In each call, I need to perform some database operations. The issue is at a time multiple db connections get opened & close. So to avoid it, I want to implement Queue of objects to be sent to database and then want…
Priya
  • 1,375
  • 8
  • 21
  • 45
0
votes
2 answers

How do I limit write operations to 1k records/sec?

Currently, I am able to write to database in the batchsize of 500. But due to the memory shortage error and delay synchronization between child aggregator and leaf node of database, sometimes I am running into Leaf Node Memory Error. The only…
0
votes
0 answers

dont wait until function finishes to run another function

Hello I am creating this script where I create a post request that adds an item to cart and selects the size all in the backend. As it runs it opens up a loading html and I wanted to have the current item that is being added's info added into a…
user9510595
0
votes
1 answer

acquire() and release() lock operations with testandset()

I need to solve the following problem: a. Show how to implement acquire() and release() lock operations using TestandSet instruction. b. Identify a performance problem, that could occur in your solution when it runs on a multiprocessor, but does…
Terence Lyu
  • 319
  • 1
  • 3
  • 13
0
votes
0 answers

Use of Yield in multi-threading

I have just started learning threads. So i was trying to write few thread based programs.I wanted to print alphabets and numbers one after the other. I used wait and notify for this. Now, I want to use yield for the same. public class Y { …
0
votes
5 answers

Printing Alphabets and Numbers using multi-threading

I have just started learning threads and pretty new to it.I'm trying to print alphabets and numbers one after the other.I have synchronized them using a flag but of no use. public class Alphabets { public static void main(String[] args) { …
0
votes
2 answers

Use of Multi Threading for printing Odd and Even Numbers

I'm pretty new to threads and just trying to get a grip on the basics.So, I tried the following code to print odd and even numbers one after the other. But I'm getting a null pointer. public class P { public static void main(String[] args) throws…
0
votes
1 answer

Does a thread acquiring monitor lock of object also acquires the object lock of superclass?

When a thread acquires monitor lock of an object (say class B) does it acquires the monitor lock of the object belonging to it's superclass (say class A, where B extends A) ? Observation #1 - When a thread (that owns the monitor lock of derived…
0
votes
2 answers

Locking instances with synchronized block inside non-static method

Going by the below code, I have two instances of class A - a1 and a2. And calling the method foo() on both the instances separately. There is a synchronized block within the foo() method, which is locked on the calling object. Since it is an…
0
votes
1 answer

What is disadvantage of calling sleep() inside mutex lock?

For example: pthread_mutex_lock(); //Do something sleep(1); //causes issues waiting while holding lock pthread_mutex_unlock(); what is the solution if we don't want to use sleep inside mutex lock
0
votes
1 answer

VB.net updating label from other thread

I have probably read and tried a hundred different ways to do this, and I can't take it any longer or wrap my head around it. I am new to multi-threading and usually make the UI process the code. I found the error of my ways as my program grew. Now…
0
votes
1 answer

Image Histogram Implementation with Metal on macOS

I am aware of MPSImageHistogram, but I'd like to implement the algorithm myself to understand Metal better. However, I run into thread synchronization problem when trying to accumulate pixel information into histogram bins, and I got no clue how to…
AQUArch
  • 1
  • 1
  • 2
0
votes
0 answers

how to implement a set of persistent coordinated worker threads

I want to reuse a set of worker threads. Each worker thread performs independent work but they must start and stop processing as a coordinated team. I need an efficient means for each worker thread to block until the main thread tells them all to…
pidloop
  • 1
  • 2
0
votes
5 answers

Atomic variables in synchronized blocks

I'm referring to the Java language but I think it can concern other languages as well. The question is: does it make sense to put an atomic variable in a synchronized block? Or the fact that the synchronized block will not be executed by two…
Luke
  • 1,633
  • 3
  • 23
  • 37
0
votes
0 answers

Synchronizing two senders and receiver threads

I have the following problem, I have 2 senders, that send one after each other, and only after 2 of them sent the message, I want a receiver to start receiving and then wait for the next two sends, e.g. S1 S2 Rec S1 S2 Rec... semOne =…
SimpleThings
  • 147
  • 2
  • 12