solaris上的boost库信号量
boost library semaphores on solaris
我在RHEL中使用boost信号量,目前我正在将代码移植到solaris 10。我遇到了一个奇怪的问题,即提升信号量不能正常工作。
我使用boost网站上的示例创建了匿名信号量。信号量在开发机器上运行良好,但在测试机器上无法运行。一个进程在发布到另一个进程后被困在等待状态,但另一个尚未脱离等待状态。
这是我的信号量减速:
...
//in global space
struct iSema
{
interprocess_semaphore ASync;
interprocess_semaphore BSync;
iSema()
:ASync(0), BSync(0)
{}
}*m_Sema;
mapped_region SemaRegion;
#define SHM_SIZE 512
...
...
//in main process 1
try
{
std::size_t ShmSize = SHM_SIZE;
shared_memory_object::remove("xyz"); //remove previous instance
shared_memory_object shm(create_only, "xyz", read_write); //create new
shm.truncate(sizeof(struct iSema));
mapped_region region(shm, read_write); //get into local scope region
SemaRegion.swap(region); //swap with global scope region
m_Sema = new (SemaRegion.get_address()) (struct iSema); //map it
}
catch(exception& e)
{//logging
}
...
//Do some thing
m_Sema->ASync.post();
m_Sema->BSync.wait();//stuck at this place
...
...
//in main second process
try
{
std::size_t ShmSize = SHM_SIZE;
shared_memory_object shm(open_only, "xyz", read_write);
shm.truncate(sizeof(struct iSema));
mapped_region region(shm, read_write);
SemaRegion.swap(region);
m_Sema = new (SemaRegion.get_address()) (struct iSema);
}
catch(exception& e)
{
//logging
}
m_Sema->ASync.wait();
m_Sema->BSync.post();
...
系统信息:
solaris 10
gcc:4.1.2使用binutils 2.18 自行构建
提高1.47
sparc体系结构
这完全与信号量和solaris实现的使用有关。在我的案例中,进程1在进程2打开信号量的共享内存之前发布。因此,流程二没有从流程一得到任何帖子。我得到了上面的代码,下面列出了一些小的更改:
...
//in global space
struct iSema
{
interprocess_semaphore ASync;
interprocess_semaphore BSync;
interprocess_semaphore CSync;
iSema()
:ASync(0), BSync(0), CSync(0)
{}
}*m_Sema;
mapped_region SemaRegion;
#define SHM_SIZE 512
...
...
//in main process 1
try
{
std::size_t ShmSize = SHM_SIZE;
shared_memory_object::remove("xyz"); //remove previous instance
shared_memory_object shm(create_only, "xyz", read_write); //create new
shm.truncate(sizeof(struct iSema));
mapped_region region(shm, read_write); //get into local scope region
SemaRegion.swap(region); //swap with global scope region
m_Sema = new (SemaRegion.get_address()) (struct iSema); //map it
}
catch(exception& e)
{//logging
}
...
//Do some thing
m_Sema->CSync.wait();
m_Sema->ASync.post();
m_Sema->BSync.wait();
...
...
//in main second process
try
{
std::size_t ShmSize = SHM_SIZE;
shared_memory_object shm(open_only, "xyz", read_write);
shm.truncate(sizeof(struct iSema));
mapped_region region(shm, read_write);
SemaRegion.swap(region);
m_Sema = new (SemaRegion.get_address()) (struct iSema);
}
catch(exception& e)
{
//logging
}
m_Sema->CSync.post();
m_Sema->ASync.wait();
m_Sema->BSync.post();
...
相关文章:
- 删除旧的信号量系统V
- 父进程和子进程之间的 POSIX 信号量
- 访问共享内存而不使用易失性、std::atomic、信号量、互斥锁和自旋锁
- 多线程.如果我使用信号量,我可以在开始时创建很多线程还是应该只有几个线程?
- C/C++ - 用于按顺序打印数字的 sem_t 类型的单个信号量
- 单车道桥 使用信号量进行同步
- 用于 64 位/32 位 IPC 的 POSIX 信号量的替代方案?
- 这个餐饮哲学家问题(dpp)的解决方案是如何工作的?互斥体和信号量
- 发布信号量返回错误 6(无效句柄)
- 在 C Linux 中使用三个线程使用信号量同步按顺序打印 3 4 5 50 次
- 在使用 pthread 和信号量实现生产者-消费者问题时需要帮助
- 如何让一个线程继续,而另一个线程正在等待C++中的信号量
- 实现信号量
- 计算信号量还是互斥体?
- POSIX 信号量在高争用/负载下不起作用
- C++:提升:托管共享内存是否需要信号量锁
- 信号量的问题
- 如何使用Windows API直接将进程"assign"到信号量?
- 从主线程C++更新信号量
- solaris上的boost库信号量