2

I'm wondering if my implementation should expect that reentrant mutex's are supported or not. The code is supposed to portable/platform independent. I'm wondering if mutex recursion is common enough that it shouldn't be a concern.

kvn
  • 1,295
  • 11
  • 28
  • Do you mean recursive acquisition of a critical section? – Michael Goldshteyn Oct 19 '10 at 14:46
  • Do you mean locking the same mutex multiple times? Or do you mean locking multiple mutexes? Also, are you using pthreads or something else? – Jonathan Oct 19 '10 at 14:46
  • One answer is, "on all platforms". A mutex has a specific meaning. However, you could expand your question, a lot. As others said, what do you mean with "mutex"? Since you talk about platforms, presumably some OS construct. Which? Be more specific or any answer will either be exceedingly vague or possibly answering something totally different from what you want to know. – Prof. Falken Oct 19 '10 at 14:49
  • I mean recursive I suppose. I guess thats what all the kids are calling it. – kvn Oct 19 '10 at 14:49
  • Well, @Kevin, then the answer is "on all platforms" if you use a mechanism which works like a mutex should: https://secure.wikimedia.org/wikipedia/en/wiki/Mutual_exclusion – Prof. Falken Oct 19 '10 at 14:50
  • pthreads are not necessarily used but are likely. There is a porting layer defining a mutex interface so the implementation can vary depending on the platform. – kvn Oct 19 '10 at 14:53
  • @Michael Yes. Thats what I mean. – kvn Oct 19 '10 at 14:54
  • I'll try editing my question to be more clear. – kvn Oct 19 '10 at 14:56

1 Answers1

4

It's usually a distinct option, available through a different function call. Even then it isn't "detected" it's just "permitted".

Sometimes, you WANT the lock to be recursive. Sometimes, you DON'T want the lock to be recursive. Any solution you come up with without explicitly allowing both conditions will not work universally for every mutex solution available without you imposing some contraints that don't exist in the libraries you'll be wrapping.

San Jacinto
  • 8,774
  • 5
  • 43
  • 58