Is it possible to use mutex in multiprocessing case on Linux/UNIX ?

后端 未结 5 864
[愿得一人]
[愿得一人] 2020-11-27 03:07

This is an interview question.

Is it possible to use mutex in multiprocessing case on Linux/UNIX ?

My idea: No, different processes have separate memory s

5条回答
  •  Happy的楠姐
    2020-11-27 03:08

    Not quite. POSIX threads has a concept of a process-shared attribute which can be used to create mutexes that can be operated on by multiple processes.

    You can put such a mutex in shared memory so that multiple processes can all get at it.

    Whether LINUX implements this., I'm not sure, I've never had a need to use it since it seems unnecessarily complex.

    For a useful precis of attributes, see my answer to this question.

提交回复
热议问题