mutex

Cannot unlock Mutex

Note: I am using the open source Poco C++ libraries I have a parent thread that creates many child threads to deal with incoming connections, each of these child threads maintains an XML document, which the parent thread can request at anytime via callback. Therefore I have a mutex protecting this document. My problem arises in tha...

Can some one Explain Mutex and How that is used

I read few documents about Mutex and the only Idea I have got still is This helps preventing threads from accessing a resource that is already being used by another resource. I got from Code snippet and executed Which Works fine: #include <windows.h> #include <process.h> #include <iostream> using namespace std; BOOL FunctionToWriteT...

How to cause locks to be freed in one thread which were set by another

I have a simple thread pool written in pthreads implemented using a pool of locks so I know which threads are available. Each thread also has a condition variable it waits on so I can signal it to do work. When work comes in, I pick a thread by looking finding an available thread from the lock pool. I then set a data structure associate...

How can/In what cases can a mutex be locked multiple times in the same thread?

I do not understand the use of a mutex if it can be recursively locked by a thread. Why would anyone want to recursively lock the mutex ? In what cases will they use this ? ...

Trade off between a recursive mutexes V a more complex class?

I've heard that recursive mutexs are evil but I can't think of the best way to make this class work without one. class Object { public: bool check_stuff() { lock l(m); return /* some calculation */; } void do_something() { lock l(m); if (check_stuff()) { /* ... */ } ...

Is it possible to do static initialization of mutexes in Windows?

pthread supports static initialization of pthread_mutex_t using PTHREAD_MUTEX_INITIALIZER. Is it possible to achieve a similar static mechanism for mutex initialization using Windows mutex? ...

How to remove a Mutex on WinXP

Hello, We have a Mutext in our C# .Net Application created by following statement: new Mutex(true, "MutexName", out pobjIOwnMutex); Actually we have no problem with it, but since a while the Application can not take the ownership of this mutex anymore. This happens only on my developer pc. If I change the mutex name it is no pro...

Should I protect operations on primitive types with mutexes for being thread-safe in C++?

What is the best approach to achieve thread-safety for rather simple operations? Consider a pair of functions: void setVal(int val) { this->_val = val; } int getVal() { return this->_val; } Since even assignments of primitive types aren't guaranteed to be atomic, should I modify every getter and setter in the program in th...

how efficient is locking an unlocked mutex? how much does a mutex costs?

Hi, In a low level language (C, C++ or whatever): I have the choice in between either having a bunch of mutexes (like what pthread gives me or whatever the native system library provides) or a single one for an object. How efficient is it to lock a mutex? I.e. how much assembler instructions are there likely and how much time do they t...

how efficient is a try_lock on a mutex?

Possible Duplicate: how efficient is locking an unlocked mutex? how much does a mutex costs? How efficient is a try_lock on a mutex? I.e. how much assembler instructions are there likely and how much time are they consuming in both possible cases (i.e. the mutex was already locked before or it was free and could be locked). ...

Mutex Initialization -(UNIX)

In the following code.A mutex is initialized.what is the significance of NULL. pthread_mutex_init(&a->monitor,NULL); I want to know why we pass NULL as the second parameter. ...

Why need a null mutex?

Why would one need a mutex object where the Acquire and release methods just return 0? I am studying the ACE framework and it has a Null_Mutex class, and I was wondering how it would come to use. class Null_Mutex { public: Null_Mutex (void) {} ˜Null_Mutex (void) {} int remove (void) { return 0; } int acquire (void) const { return 0; } ...

Multiprocess conditional/named Lock

In a multiprocess program I want to lock certain function based on arguments e.g. def calculate(spreadsheet): _do_calc(spreadsheet) Now what I want to do is based on spreadsheet, lock the function so that multiple spreadsheets can be worked on concurrently but two calls on same spreadsheet will lock e.g. def calculate(spreadsheet...

why does `try_lock`s performance behaves always like `lock`on a mutex?

On a mutex: I was asking about the performance of lock here and about the performance of try_lock here. The question about try_lock was closed as exact duplicate to the one about lock. However, I fail to see why try_lock must behave in the same way as lock in every possible mutex implementation. As this question was not really answered...

Boost Try lock Assert

Hi, I am using boost::recursive_mutex. But when I use try_lock on this for the first time I am getting following error CollisionAvoidance: /usr/include/boost/thread/pthread/recursive_mutex.hpp:78: bool boost::recursive_mutex::try_lock(): Assertion `!res || res==16' failed. What is the reason for this? ...

maximum number of mutexes per process/thread in windows

Is there a limit in the maximum number of mutexes per process/thread in a Asp.net application? Just in case the target operating systems are: Windows XP Pro, server 2003/2008 and Windows 7 in the near future. Usually the website is deployed in an App Pool. ...

Using boost::lock_guard for simple shared data locking

I am a newcomer to the Boost library, and am trying to implement a simple producer and consumer threads that operate on a shared queue. My example implementation looks like this: #include <iostream> #include <deque> #include <boost/thread.hpp> boost::mutex mutex; std::deque<std::string> queue; void producer() { while (true) { ...

pthreads mutex number and performance

how many pthreads mutex are usually available in a typical system? Is having many pthreads mutex degrades performance? ...

Inter-process lock

I am writing a system for automatically recalculating the results of costly methods, and then storing them in a cache. The cache may be distributed, meaning (obviously) multiple processes can access it. On the first invocation of the method to cache the result for, I want to spawn a thread that will periodically recalculate the result o...

How to use boost::thread mutex to synchronize write access?

I have a newbie question about Boost::Thread and Mutex. I would like to start many parallel instances of the following Worker, and all of them write to the same std::vector: struct Worker { std::vector<double>* vec; Worker(std::vector<double>* v) : vec(v) {} void operator() { // do some long computation and then add results t...