Linux Shared Memory Synchronization

后端 未结 4 604
天命终不由人
天命终不由人 2021-02-06 03:24

I have implemented two applications that share data using the POSIX shared memory API (i.e. shm_open). One process updates data stored in the shared memory segment

4条回答
  •  半阙折子戏
    2021-02-06 04:10

    Might as well make this an answer.

    You can use sem_init with pshared true to create a POSIX semaphore in your shared memory space. I have used this successfully in the past.

    As for whether this is faster or slower than a shared mutex and condition variable, only profiling can tell you. On Linux I suspect they are all pretty similar since they rely on the "futex" machinery.

提交回复
热议问题