首页| 论坛| 消息

标题:这个是否有办法解决?
作者:wwwfffhhh
日期:2021-02-02 21:27
内容:

采用QT5.15.2,操作系统为Ubuntu18.04(在Vmware下运行),
编写下面的两个通过QSystemSemaphore同步的进程,将会发现异常(已经确认该程序在window 10操作系统下没有问题)
服务端程序:
QSystemSemaphore InvalidDataSysSemaphore("TestKeyInvalid",1);
QSystemSemaphore ValidDataSysSemaphore("TestKeyValid");
quint32 ReceiveTimeCount = 0;
while(1)
{
if(ValidDataSysSemaphore.acquire())
{
ReceiveTimeCount++;
InvalidDataSysSemaphore.release();
if(ReceiveTimeCount>=32765)
qDebug("等待成功次数=%d", ReceiveTimeCount);//这里只能接收到32767次,后面不会接收,但重新启动程序将可能会莫明其妙继续收到信号量
}
else
{
qDebug("等待错误,已经等待次数=%d", ReceiveTimeCount);
break;[/b ..


#1 [wwwfffhhh 02-03 09:37]
原来在虚拟机中测试,现在在实体机中测试,也是发送了32767次QSystemSemaphore信号量后,就不能发送了。
现在这个问题看起来比较严重,不知道该如何解决?
希望大家帮助找找解决方案,先谢谢大家了!
#2 [kaon 02-03 09:53]
https://bugreports.qt.io/browse/QTBUG-8497
好像一直没解决过
#3 [kaon 02-03 09:54]
For those looking for a workaround: have an own counter for the released semaphores. after n > 32000 call setKey() with the CREATE flag. This will reset the unix-counter. (Attention: this will reset your semaphore count too).
if ( n++ > 32000 )
{ systemSemaphore->setKey(sameKey, newInitialValue, QSystemSemaphore::Create) }
#4 [wwwfffhhh 02-03 14:21]
看起来调用setKey(...)函数就可以了,因为我的程序中采用双信号量,所以setKey(...)的参数中 newInitialValue=0是没问题的,否则程序将可能死锁的。
现在就只能先这么用了。
谢谢 kaon!

回复 发表
主题 版块