pthread mutex not working correctly

前端 未结 2 856
夕颜
夕颜 2020-12-06 21:33

I am currently learning C from MIT\'s Open Courseware course called Practical Programming in C. In discussing race conditions in multithreading, the lecture notes contained

2条回答
  •  春和景丽
    2020-12-06 22:03

    The reason why it works with linux is, because under linux :

    #define PTHREAD_MUTEX_INITIALIZER { { 0, 0, 0, 0, 0, { 0 } } }
    

    which is exactly how the mutex is initialized anyway, since it is a .bss-variable.

    Under MacOSX, it is some other magic value:

    #define PTHREAD_MUTEX_INITIALIZER {_PTHREAD_MUTEX_SIG_init, {0}}
    #define _PTHREAD_MUTEX_SIG_init     0x32AAABA7
    

    so it indeed has to be initialized to have it working correctly.

提交回复
热议问题