Linux共享内存同步 [英] Linux Shared Memory Synchronization

查看:143
本文介绍了Linux共享内存同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了两个使用POSIX共享内存API(即shm_open)共享数据的应用程序.一个进程更新存储在共享内存段中的数据,而另一个进程读取它.我想使用某种互斥或信号量来同步对共享内存区域的访问.最有效的方法是什么?我正在考虑的一些机制

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 and another process reads it. I want to synchronize the access to the shared memory region using some sort of mutex or semaphore. What is the most efficient way of do this? Some mechanisms I am considering are

  • 存储在共享内存段中的POSIX互斥锁(需要设置PTHREAD_PROCESS_SHARED属性)
  • 使用semget
  • 创建System V信号灯
  • A POSIX mutex stored in the shared memory segment (Setting the PTHREAD_PROCESS_SHARED attribute would be required)
  • Creating a System V semaphore using semget

推荐答案

我不是使用System V信号灯,而是使用sem_open()等命名为POSIX的信号灯.

Rather than a System V semaphore, I would go with a POSIX named semaphore using sem_open(), etc.

这篇关于Linux共享内存同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆