mutex

Why does Monitor.Pulse need locked mutex? (.Net)

Monitor.Pulse and PulseAll requires that the lock it operates on is locked at the time of call. This requirement seems unnecessary and detrimental for performance. My first idea was that this results in 2 wasted context switches, but this was corrected by nobugz below (thanks). I am still unsure whether it involves a potential for wasted...

C++ context switch and mutex problem

Ok.. here is some background on the issue. I have some 'critical' code that i'm trying to protect with a mutex. It goes something like this Mutex.Lock() // critical code // some file IO Mutex.Unlock(). Now the issue is that my program seems to be 'stuck' due to this. Let me explain with an example. Thread_1 comes in; and go to Mutex...

How to alter the recursive locking behaviour of Windows Mutex?

Windows Mutex seems to allow an acquired lock to be acquired again (recursively) if the thread currently owning the lock tries to acquire it. But, posix based pthread locks don't allow such a behaviour. Is there any compile time macro or any settings which can make the windows mutex behave in the same way as the pthread mutex? ...

what kind of loop is for (;;)?

found in torvalds/linux-2.6.git -> kernel/mutex.c line 171 i have tried to find it on google and such to no avail. what does "for (;;)" instruct? ...

iPhone ExtAudioFileConvert.cpp: getting rid of mutex and thread handling...

I'm rewriting the ExtAudioFileConvert.cpp sample from Apple to do some extra output file handling... I am not going to be calling it more than once, so I should have no re-entrancy issues. I'm also rewriting it in C. Since I haven't had a lot of experience with mutex locking or thread handling, I was hoping not to copy and paste tho...

C++ Exception Handling In Critical Section (pthreads)

[Edit: (copied from a comment) As it turns out, the problem was elsewhere, but thank you all for your input.] I have a shared container class which uses a single mutex to lock the push() and pop() functions, since I don't want to simultaneously modify the head and tail. Here's the code: int Queue::push( WorkUnit unit ) { pthread_mu...

pthreads mutex vs semaphore

What is the difference between semaphores and mutex provided by pthread library ? ...

Can a managed COM object unload or terminate itself?

I have a COM object written in C# that is a toolbar for the Windows taskbar (implements IDeskSite). I want to either, Prevent the taskbar from being loaded if a certain application is running Allow the toolbar to unload itself in the case of an unhandled exception rather than allowing the exception to cause Explorer to crash For #1,...

To Mutex or Not To Mutex?

Do I need a mutex if I have only one reader and one writer? The reader takes the next command (food.front()) from the queue and executes a task based on the command. After the command is executed, it pops off the command. The writer to the queue pushes commands onto the queue (food.push()). Do I need a mutex? My reader (consumer) only e...

Designing Thread Class

I have a design question. Is it better to define separate classes for SENDING and RECEIVING. Or, is it better to define a single Thread class? I like the idea of a single Thread class because it is easier to share a queue which can be locked by mutex. Design Option #1 (Separate): mySendThread = new SendThread(); // Have thread properti...

Why is QMutex unknown?

I've included the QMutex header and using it as seen below. But I get the following error: error C2146: syntax error : missing > ';' before identifier > '_RecorderParamsMutex' error C4430: missing type specifier - int assumed. > Note: C++ does not support default-int error C4430: missing type specifier -> int assumed. ...

Difficult concurrent design

I have a class called Root which serves as some kind of phonebook for dynamic method calls: it holds a dictionary of url keys pointing to objects. When a command wants to execute a given method it calls a Root instance with an url and some parameter: root_->call("/some/url", ...); Actually, the call method in Root looks close to this:...

QMutex stuck in locked state

I have a function which is part of a class and in this function there is a mutex.lock at the beginning of the function and a mutex.unlock just before its return. Now I have encountered a situation where the mutex is stuck in the locked state. What could be doing this if this function is the only place where I use that mutex to lock and...

How to implement a singleton pattern with an infinite loop - C#

I am currently working on an application in C# that runs on an infinite loop with a Thread.Sleep call after each iteration of the other method calls. My main is - static void Main(string[] args) { bool isOnlyInstance = false; Mutex mutex = new Mutex(true, "RiskMetricsSensitivitiesDatabaseLoader", out isOnlyInstance...

Mutex not being respected in synchronized methods in Java class

I'm running into mutex issues with my Queue class under load which I'm at a loss to figure out why they are happening. objects = new ArrayList<Object>(); public synchronized int getSize(){ return objects.size(); } public synchronized Object dequeue(){ if(getSize()==0){ try { wait(); } catch (InterruptedException e) { // TOD...

Do I need to lock object when reading from it?

I am writing a program where there is an object shared by multiple threads: a. multiple write threads write to the object (all running the same function) b. a read thread which accesses the object every 5 seconds c. a read thread which accesses the object there is a user request It is obviously necessary to lock the object when writing ...

Mutex across network - C#.NET

I have a message queue on a shared system. This queue is accessed by 2 processes which run on 2 other machines. I need to control access to this queue by the 2 processes. So I need a "network mutex". How can I achieve this? I don't think this is supported out of the box in C#.NET but if I have missed something very obvious, do point me ...

Select mutex or dummy mutex at runtime

I have a class that is shared between several projects, some uses of it are single-threaded and some are multi-threaded. The single-threaded users don't want the overhead of mutex locking, and the multi-threaded users don't want to do their own locking and want to be able to optionally run in "single-threaded mode." So I would like to ...

How can I create a System Mutex in C#

How can I create a system/multiprocess Mutex to co-ordinate multiple processes using the same unmanaged resource. Background: I've written a procedure that uses a File printer, which can only be used by one process at a time. If I wanted to use it on multiple programs running on the computer, I'd need a way to synchronize this acros...

How to use the mutex code in a C# program?

I have gone through the code of mutex, but it is giving me errors like: public override void dispose(bool disposing); no suitable method found to dispose This is occurring on initialize component, so I have commented that portion, but the major error I'm facing is on the design view part: The designer cannot process the code a...