【发布时间】:2019-04-27 18:08:09
【问题描述】:
在我们的项目中,我们使用信号量在父子进程之间进行同步。执行信号量操作,并在每次同步时删除信号量。
几周后,semop 操作因“无效参数”而失败
sembuf.sem_num = 0;
sembuf.sem_op = 1;
sembuf.sem_flg = SEM_UNDO;
ret = semop( semid, &sembuf, 1 ); --> invalid arguments couple of weeks later.
semid 是正确的,我没有看到由于特定过程导致的任何信号量泄漏。
In man page i could see the possible reason for invalid argument could see below:
EINVAL The SemaphoreID parameter is not a valid semaphore identifier.
EINVAL The number of individual semaphores for which the calling process requests a SEM_UNDO flag would exceed the limit.
I am suspecting the point 2.
It is multithreaded process. So Howmany semaphore can be used at a time for a procees ?
What is the limit of "SEM_UNDO" ?
1) how to make sure that EINVAL is due to "SEM_UNDO" flag exceed limit. ?.
2) how to avoid the exceed limit ?
3) Is there any kernel variable needs to be configured for this issue (in AIX most of the kernals are dynamic)?
提前感谢您的帮助
【问题讨论】:
-
您可能已经删除了信号量 (
semctl(IPC_REMOVE)) -- 可能在另一个进程/线程中。编辑:在semget中意外重用相同的key时可能会发生这种情况。 -
我们每次都使用 semget 创建信号量,并在同步完成后删除信号量。但是过了一会儿,即使我们没有任何错误地创建新的信号量,信号量操作也会失败,参数无效
-
好吧,那你知道原因是什么了:另一个线程/进程破坏了信号量。