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
8
votes
2 answers

Handles leak (Event type) in .NET application

I have a Windows Forms application written in .NET 4.0. Recently, while execution some tests, I noticed that there is some problem with handles. Table below shows the results: As you can see the, only handle type which is increasing is Event. So my…
7
votes
2 answers

c++ multithreading synchronization

Here is a simplified version of my problem. There are N threads executing following 3 instructions in an infinite loop: A -> B -> C -> A -> B -> C -> A -> B -> ....... I want that all threads execute instruction B concurrently i.e. execution of B…
arvin
  • 113
  • 1
  • 5
7
votes
2 answers

CMutex::Lock vs. CSingleLock::Lock

I've been tapped to support some legacy code, and I'm seeing some things that cause me to scratch my head in confusion. In some sections of code, I see that a class instance uses a CMutex instance to synchronize method execution. For…
JadeMason
  • 1,181
  • 1
  • 14
  • 23
7
votes
3 answers

Multithreading for making http post requests to web service

I want to send multiple HTTP post requests to a Web Service in C# .For example , if n=3 then http post requests from 3 xml files should be made and also the response should be written in a file.Once the first 3 requests are made then the next 3…
7
votes
3 answers

warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]

This code is about. Race conditions: Scheduling and compiler behaviour play a significant role in process or thread synchronization. The simplest scenario to demonstrate the need to synchronization comes from the race conditions created between two…
Zeyad Jameel
  • 93
  • 1
  • 1
  • 3
7
votes
2 answers

Difference between class locking and object locking in Java

People tell about two types of multi-threaded locking - object and class. In my knowledge, locking is done on objects only. Case 1: On objects we create using new or factory methods etc. void synchronized myMethod(Type param) { //will lock on the…
xploreraj
  • 3,792
  • 12
  • 33
  • 51
6
votes
1 answer

Std::Lock avoids deadlock but this program gets stuck

All, Referring to the question in std::lock still caused deadlock I still couldn't figure what is the problem in the below code. Can somebody please explain the problem and how to fix this? Why does it get hung? Pls help. #include…
6
votes
2 answers

Java - Threads state when performing I/O operations

Suppose a Java thread performs some I/O operation like reading a file with traditional blocking Java I/O. The question is: What is the state of the thread while waiting? I don't know if it is RUNNING (doing some active wait) or WAITING (maybe there…
italktothewind
  • 1,950
  • 2
  • 28
  • 55
6
votes
1 answer

Mutex lock speed difference inside and outisde the foor loop

I am confused of speed different between using the mutex lock() and unlock() inside and outside a for loop. I got a global variable value and a function that increments it 1000000 times. This function is run in parallel by 5 threads. I measured the…
user1031204
  • 701
  • 1
  • 8
  • 30
6
votes
2 answers

Synchronizing on an object in Java

I am looking for something akin to this syntax even though it doesn't exist. I want to have a method act on a collection, and for the lifetime of the method, ensure that the collection isn't messed with. So that could look like: private void…
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
6
votes
3 answers

Printing Even and Odd numbers using 2 different classes

This was a question asked in one of my job interviews: You have 2 different classes (that implements Runnable) say EvenThread & OddThread. As the name suggests, the EvenThread prints only even numbers and the odd thread prints only odd numbers,…
6
votes
1 answer

Synchronization of methods, objects, class in Java

I need some clarification with regards to use of synchronization in multi-threaded environment. I have a small example Class below. but I am actually finding it hard to make a test case of how the following will work; The reason I want test case is…
eagertoLearn
  • 9,772
  • 23
  • 80
  • 122
5
votes
0 answers

Why, before calling the wait method of an object, should a thread own the monitor of exactly the same object?

I am learning about cooperation between concurrent tasks and I have got that question and a possible answer to it. I would like to make sure I understand it correctly. So to call a.wait() it is first required to synchronize on the object a or to be…
5
votes
0 answers

RxJava - synchronized block - inner Source

I want to use synchronized block for source of flatMap. But I need to use this construct for processing (method processItem), not only when inner source is created. This Observable is called each 5 minutes (for example…
5
votes
5 answers

Java Threads: How to print alphabets and numbers using two threads one at a time

I am trying to work around with threads in java. Though I understand that threads output are unpredictable, However was wondering if there is a way to do that. I have to implement two threads, one prints alphabets(a,b,c...z) and other prints…
roger_that
  • 9,493
  • 18
  • 66
  • 102
1 2
3
42 43