1

I suspect that based on the behavior of my code that if I have a boost::thread_group accessing an object protected by a boost::recursive_mutex that the mutex does not prevent threads from within the group from simultaneously entering the protected area.

This is confusing because I see all of the threads listed in the debugger (xcode).

Is this a known issue? I couldn't find any documentation on it.

Jason Harrison
  • 922
  • 9
  • 27

1 Answers1

1

A boost thread_group is a group of threads.

All the threads are, by definition, distinct and unique.


So, if your mutex fails to... "mut-ex" (mutually exclude) this indicates a programmer error elsewhere.

On a whim, I'd suggest that perhaps your expectations of mutexes (recursive or not) is not accurate (in similar way as the expectations of a thread group were)?

The thing you might have missed is that all parties accessing the shared objects /must/ acquire the mutex at all times of these accesses. It is not enough to have one thread "guard" the shared objects, to magically keep other threads out.

Mutexes are a coöperative proposition. The term "critical section" is actually a bit nicer in this respect: you "mark" the critical sections in code, as opposed to "marking" the critical data (whatever that would be).

sehe
  • 374,641
  • 47
  • 450
  • 633
  • Exactly : a mutex doesn't protect any variable or value or memory space. a Mutex is a set of doors with one single key. You put doors all around the area you want to protect and are guaranteed that only 1 thread can open any door at any moment. – Félix Cantournet Feb 04 '15 at 22:48
  • I think my understanding of mutexes is accurate enough. – Jason Harrison Feb 04 '15 at 23:52
  • @JasonHarrison Ok! Just a hunch of course, based on the few things you mentioned (it was ambiguous, so I believe you if you say you do). Feel free to disregard that part. – sehe Feb 04 '15 at 23:54