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

why do we require to synchronize StringBuffer when its methods are already synchronized

In Java Docs it says, StringBuffer's methods are synchronized. Then why do I still need to manually synchronize the StringBuffer in the example given in this question: here I read somewhere that it is not worthy of using StringBuffer over…
JPG
  • 1,247
  • 5
  • 31
  • 64
4
votes
2 answers

Why does it matter what object I use wait()/notify() on, if I just want a way to signal between threads?

So I have a classic case of "my code works, but I dont know why". I'm have a program that creates a thread, and when I receive a certain input from scanner, I pass control of the string to a worker thread. To do this, I make my thread wait(), and…
Eric S.
  • 1,502
  • 13
  • 31
4
votes
4 answers

Thread synchronization with mixed C and C++

I have a multithreaded program with the main thread being third-party (can't change it) and pure C. My task is to build new modules (in C++) around it, those reside partly in other threads and need to use the C program's interface. Basically just…
fewu
  • 229
  • 1
  • 10
4
votes
1 answer

Notifications in multithreading

I am a java programmer and I am having a conceptual doubt in threads. I just want to know a thread will enter into which state in 2 conditions. When you join a thread in which state will the joined thread enter into? When a waiting thread is…
ravikumar
  • 101
  • 1
  • 3
4
votes
0 answers

Application gets crashed and displays a Error in Thread(Fatal Signal)

In LogCat : 12-16 01:49:49.139: A/libc(790): Fatal signal 11 (SIGSEGV) at 0x0000000c (code=1), thread 806 (Thread-93) 12-16 01:49:49.169: A/libc(790): Fatal signal 11 (SIGSEGV) at 0x0000000c (code=1), thread 824 (Thread-112) I wrote a code for…
Venus
  • 219
  • 1
  • 3
  • 13
4
votes
3 answers

How to Share a Object between two threads (Thread Synchronization)?

I have two threads. One records the audio data into the variable. Another Thread sends that recorded variable to the server. What do I need to do in terms of concurrency, since I am new to multi-threading? Below is the code snippet: short[] sData =…
G M Ramesh
  • 3,420
  • 9
  • 37
  • 53
3
votes
1 answer

Learning to implement thread pool - signaled events getting lost when using autoresetevent

I am a strong believer in learning by reinventing. With that state of mind, I set out to implement custom thread pool. The objective that I set for myself was following: To be able to queue work items on the thread pool. To be able to process work…
3
votes
2 answers

Are user scoped application settings (created in the VS designer) thread safe?

I have created application settings in my visual studio project, containing both user scoped settings and application scoped settings. My application has several threads that may access the settings for read or write simultaneously. I've searched…
user1039580
  • 359
  • 5
  • 15
3
votes
3 answers

Wait till I receive signal in Java multi thread

I have a multi threaded application which receives asynchronous messages. How to wait till message is received (or timeout)?Is there a better way to do this with wait() and notify()? I tried to do this with raw thread sleep with atomic…
3
votes
1 answer

Thread synchronization

Data has to be shared between threads. Which is the best synchronization method? Does the lock is the better approach or Mutex? namespace ConsoleApplication8 { class Data { public int X { set; get; …
Raghaav
  • 243
  • 1
  • 2
  • 5
3
votes
0 answers

Why have some threading problems been solved without extending java.lang.Object?

Some threading problems were solved without extending java.lang.Object. The methods wait(), notify() and notifyAll() are implemented on Object, which seems to me not to be the best decision since it pollutes the class's interface. It affects all…
aboger
  • 2,214
  • 6
  • 33
  • 47
3
votes
5 answers

Does thread-safe mean no race conditions?

ConcurrentHashMap is thread-safe, but race conditions can occur, because as I understand only parts of the map are locked and only for write operations meaning that if there is a read operation at the same time there will be a race condition. But I…
3
votes
2 answers

Why is this code throwing IllegalStateMonitorException

I am trying to create a Blocking Queue using notifyAll() and wait() methods with a shared object. But this code throws IllegalMonitorStateException. Where do I need to make the change? public class BlockingQueueNotifyAll { private Queue
3
votes
2 answers

Why there is requirement of Thread safe collection?

Why we need a thread-safe collection if we easily convert a non-thread-safe collection to Thread safe. Ex: we can create Synchronized ArrayList by using Collections.synchronizedList() method.
3
votes
1 answer

Thread Synchronization for DoFn in Apache Beam

I am writing a DoFn in which its instance variable elements (i.e., a shared resource) can be mutated in the @ProcessElement method: import java.util.ArrayList; import java.util.List; import org.apache.beam.sdk.transforms.DoFn; public class…
Kuan Lin
  • 75
  • 2
  • 7