Do pthread mutexes work across threads if in shared memory?

前端 未结 3 1020
天涯浪人
天涯浪人 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条回答
  •  萌比男神i
    2020-12-01 06:24

    If your C/pthread library is conforming, you should be able to tell if it supports mutexes shared across multiple process by checking if the _POSIX_THREAD_PROCESS_SHARED feature test macro is defined to a value other than -1 or by querying the system configuration at run-time using sysconf(_SC_THREAD_PROCESS_SHARED) if that feature test macro is undefined.

    EDIT: As Steve pointed out, you'll need to explicitly configure the mutex for sharing across processes assuming the platform supports that feature as I described above.

提交回复
热议问题