Questions tagged [recursive-mutex]

A recursive mutex (reentrant mutex) is a mutex which may be locked multiple times by the same process or thread, without causing a deadlock.

A recursive mutex (reentrant mutex) is a mutex which may be locked multiple times by the same process or thread, without causing a deadlock.

See also:

41 questions
3
votes
2 answers

Boost condition_variable argument error

I encounter an error in the code below. recursive_mutex m_RecurMutex; condition_variable cond; unique_lock lock(m_RecurMutex); cond.wait(lock); // Error Here. What is the reason causing this error?
nicholas
  • 2,581
  • 14
  • 66
  • 104
3
votes
3 answers

Non-recursive mutex ownership

I read this answer on SO: Because the recursive mutex has a sense of ownership, the thread that grabs the mutex must be the same thread that releases the mutex. In the case of non-recursive mutexes, there is no sense of ownership and any thread can…
jasonline
  • 8,646
  • 19
  • 59
  • 80
2
votes
1 answer

C - Mutex attributes

Can I create and use only one mutex attribute to initialize multiple recursive mutexes? Or do I have to create one mutex attribute for each mutex I want to create? Basically I the following code correct? int err; int bufferLength =…
Daniel Oliveira
  • 1,280
  • 14
  • 36
2
votes
1 answer

Lower bound for the maximum level of ownership for recursive_mutex?

Quoting [thread.mutex.recursive]: A thread that owns a recursive_mutex object may acquire additional levels of ownership by calling lock() or try_lock() on that object. It is unspecified how many levels of ownership may be acquired by a single…
jotik
  • 17,044
  • 13
  • 58
  • 123
2
votes
1 answer

How can implement a recursive lock using boost, that spans multiple methods?

I have a class that opens transactions, adds operations to a queue, then closes the transaction. Across the open->close lifetime I would like to employ a recursive mutex, so that only one thread can have a transaction open at any time. All other…
MM.
  • 4,224
  • 5
  • 37
  • 74
1
vote
0 answers

Pthreads: First mutex lock call on 'recursive' mutex type sometimes has behaviour of a 'normal' mutex

Design: A singleton that contains a 'recursive' mutex resource. 2 threads use this singleton to update/manage data. Singleton is created whichever thread tries to access it first. Singleton creation has a global lock to ensure we call mutex attr…
Harry
  • 21
  • 4
1
vote
1 answer

Will boost::recursive_mutex::scoped_locks destructor reference an unlocked mutex?

After calling unlock() on a boost::recursive_mutex::scoped_lock, will the lock object reference the mutex somehow in its destructor? The lock still retains a reference to the mutex after the call to unlock (ie. mutex() returns the same pointer).…
Viktor
  • 3,295
  • 2
  • 25
  • 26
1
vote
0 answers

pthread_recursive_mutex_initializer_np vs pthread_mutex_initializer

Other than the answer given in What is the difference between PTHREAD_RECURSIVE_MUTEX_INITIALIZER and PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP? I would like to know what are the other differences between these two.
Hari Nandha
  • 254
  • 2
  • 5
1
vote
1 answer

Is it possible to conveniently access the count of _thread.RLock via ctypes?

It is possible to create a count property for threading._RLock._count by inheriting from the class and exposing the data from the underlying attribute. This is easily demonstrated by example: import threading # noinspection PyProtectedMember class…
Noctis Skytower
  • 21,433
  • 16
  • 79
  • 117
1
vote
1 answer

Recursive mutex with FSU Pthread implementation

I am wondering whether the Florida State University implementation of the pthread standard is, by any chance, able to handle the recursive mutexes. Unfortunately the documentation about the FSU implementation is rather poor, and it does not mention…
1
vote
2 answers

Why C++ concurrency in action listing_6.1 does not use std::recursive_mutex

I am reading the book "C++ Concurrency In Action" and have some question about the mutex used in listing 6.1, the code snippet is below: void pop(T& value) { std::lock_guard lock(m); if(data.empty()) throw empty_stack(); …
vmcloud
  • 650
  • 4
  • 13
1
vote
3 answers

Why boost::recursive_mutex is not working as expected?

I have a custom class that uses boost mutexes and locks like this (only relevant parts): template class FFTBuf { public: FFTBuf(); [...] void lock(); void unlock(); private: T *_dst; …
Kjir
  • 4,437
  • 4
  • 29
  • 34
1
vote
1 answer

error check mutex vs recursive mutex

I was wondering if I could make a recursive mutex type on my own with a PTHREAD_MUTEX_ERRORCHECK mutex, this is the result: typedef struct { pthread_mutex_t mutex; uint32_t deadlocks; pthread_t owner; BOOL isLocked; }…
Marco
  • 7,007
  • 2
  • 19
  • 49
1
vote
1 answer

How does the recursive(reentrant) mutex works?

I read two articles at http://preshing.com/20120305/implementing-a-recursive-mutex as well as http://en.wikipedia.org/wiki/Reentrant_mutex on recursive(reentrant) mutex, but neither article made any sense. Could someone explain how…
newprint
  • 6,936
  • 13
  • 67
  • 109
1
vote
2 answers

Recursive mutex on Windows?

As far as I understand, on Windows CRITICAL_SECTION can be used only as a non-recursive mutex. To get recursive mutex you have to use OpenMutex and friends. However, AFAIU, Win32 Mutex cannot be used with condition variable…
Martin Sustrik
  • 783
  • 10
  • 22