When to use recursive mutex?

后端 未结 6 586
旧时难觅i
旧时难觅i 2020-11-30 19:36

I understand recursive mutex allows mutex to be locked more than once without getting to a deadlock and should be unlocked the same number of times. But in what specific sit

6条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 20:23

    If you want to see an example of code that uses recursive mutexes, look at the sources for "Electric Fence" for Linux/Unix. 'Twas one of the common Unix tools for finding "bounds checking" read/write overruns and underruns as well as using memory that has been freed, before Valgrind came along.

    Just compile and link electric fence with sources (option -g with gcc/g++), and then link it with your software with the link option -lefence, and start stepping through the calls to malloc/free. http://elinux.org/Electric_Fence

提交回复
热议问题