Do pthread mutexes work across threads if in shared memory?

前端 未结 3 1013
天涯浪人
天涯浪人 2020-12-01 05:48

I found this: Fast interprocess synchronization method

I used to believe that a pthread mutex can only be shared between two threads in the same address space

3条回答
  •  情深已故
    2020-12-01 06:13

    You need to tell the mutex to be process-shared when it's inited:

    http://www.opengroup.org/onlinepubs/007908775/xsh/pthread_mutexattr_setpshared.html

    Note in particular, "The default value of the attribute is PTHREAD_PROCESS_PRIVATE", meaning that accessing it from different processes is undefined behaviour.

提交回复
热议问题