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

Segmentation fault threads

I have written this code that simulates a parking system, however I have a problem when I have to reuse a struct that contains a messageQueue to my carthread. The problem occurs when I try to communicate to the handler for exit with ID_CAR_IND. The…
lenni
  • 1
  • 1
  • 2
-2
votes
1 answer

Analysing a Thread dump using java

I have a thread dump. Now, I want to know how many threads are running, what is their run time, what is its current state. I don't want to use third party tools. I need a java code which takes dump file as input and shows the o/p.The main purpose is…
-2
votes
1 answer

How to test threads

We have threads: module Task def self.execute "result" end end threads = [] threads << Thread.new { Task.execute } We need to specify the test that checks the result: expect(Task.execute).to eq("result") We added a thread inside a…
Alex Strizhak
  • 910
  • 1
  • 12
  • 22
-2
votes
1 answer

Is there a limit on the number of threads that can simultaneously acquire reader lock (SRW)?

In my application, for the concurrency, I am using Slim Reader Writer lock on Windows and pthread_rwlock_t on Mac/Linux. I am seeing a weird test failure that makes me wonder if there is a limit on the number of threads that can possess the reader…
-2
votes
2 answers

Does Java synchronized block work same with "this" and with a method parameter?

How Java synchronization behaves if a method parameter is used in the synchronization block instead of this keyword. public void doSomething(final MyInterface iface) { synchronized(this) { // ... do some work } } vs public void…
Niranjan
  • 2,601
  • 8
  • 43
  • 54
-2
votes
2 answers

Read/Write lock using only critical section causes deadlock

After going through this question with the same title and its answers, I thought to try something that should really work only using critical section and thus should be much faster that existing solutions (which use other kernel objects too like…
Atul
  • 3,778
  • 5
  • 47
  • 87
-2
votes
3 answers

Prioritized method execution in Object

In my application I have an object called 'manager'.My main thread is continously calling manager.sendData(..); I also want to have a thread spawned from my main thread where I make get request to a server periodically and upon any response I…
Nitin J
  • 78
  • 1
  • 2
  • 9
-3
votes
1 answer

C# create multiple tasks, execution per task is slower than one not parallel

i have this part of code bool hasData = true; using (Context context = new Context()) { using (SemaphoreSlim concurrencySemaphore = new SemaphoreSlim(MAX_THREADS)) { while (hasData) { Message message =…
-3
votes
1 answer

Blocking a thread for longer than Int32.MaxValue

I am working on a project that needs to block a running thread for a time span that can vary between one second and several months. The approach I came up with was to use the EventWaitHandle.WaitOne method (or any of its siblings) with a timeout…
-3
votes
2 answers

Consumer, producer- mutex, sync- critical section

I've tried typical some example of multithreading, after that I would like to try typical producer-consumer problem. (Producer can produce if there's space and also if consumer is not consuming and vice versa) But I have problem with…
xxxvodnikxxx
  • 1,270
  • 2
  • 18
  • 37
-3
votes
1 answer

Why is output not synchronize?

I am trying to learn multi-threading public class WithSynchronizeMethodObject extends Thread { SharedObject obj; WithSynchronizeMethodObject() { } WithSynchronizeMethodObject(SharedObject o) { obj=o; } …
Akhil Jain
  • 13,872
  • 15
  • 57
  • 93
-4
votes
1 answer

Why C# compiler copies variable for locking?

My original code is such like Object mylock = new object(); void Test() { lock(mylock) { } } Compiled into the following code void Test { object obj = mylock; // add a temporary variable bool lockTaken = false; …
-4
votes
1 answer

Threads and synchronisation using pipe in c++

I have two threads. one thread generate a number and the other squares the number generated. I need to synchronise this action using pipes or semaphore or message queues . Help me with this problem
-6
votes
2 answers

Do I need to synchronize access to a HANDLE on Windows?

I have a HANDLE to the waitable timer that can be shared among many running threads in my Windows service for the APIs such as CreateWaitableTimer, WaitForSingleObject, SetWaitableTimer and CancelWaitableTimer. My question is, do I need to…
c00000fd
  • 20,994
  • 29
  • 177
  • 400
-13
votes
1 answer

How to prevent method from running in multiple instances

I created a method that polls a database. If two instances of the exe are run, I wouldn't want both instances to be able to run the polling method simultaneously. How might I best ensure the polling method is only ever active in one thread…
BVernon
  • 3,205
  • 5
  • 28
  • 64
1 2 3
42
43