1

Is there a simple way to print/show what's the current status of a mutex (pthread_mutex_t)? I can't find any function for this purpose.

rkachach
  • 16,517
  • 6
  • 42
  • 66
  • 1
    Mutexes don't really report status in C, you usually have to do this manually with condition variables. Does this question help you at all? http://stackoverflow.com/questions/4362459/check-to-see-if-a-pthread-mutex-is-locked-or-unlocked-after-a-thread-has-locked – Dan Oct 05 '16 at 05:20
  • The code in this case only uses pthread_mutex_t and I'm having some strange issues with threads synchronization. Thus I want to print the status for each mutex for debugging. – rkachach Oct 05 '16 at 05:37
  • 1
    I think you want to use condition variables. Just have some basic integer primitives flag different messages when your mutexes run through different parts of the code. To synchronize you'd just check your condition variables for the optimal condition, then proceed or halt as needed. – Dan Oct 05 '16 at 05:43
  • I can't change the source code. I need to debug using mutexes .. – rkachach Oct 05 '16 at 07:59
  • If you can't change the code then I'm afraid you're out of luck – Dan Oct 05 '16 at 15:18

0 Answers0