在我们的项目中,我们使用信号量在父进程和子进程之间进行同步。执行信号量操作,并在每次同步时删除该信号量。
几周后,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)?
预先感谢您的帮助
答案 0 :(得分:0)
正如我已经在评论中写道的那样,您的另一个线程/进程删除了您尝试使用的信号灯。您不应在每次使用时都创建和销毁信号量。
关闭:我承认SYSV信号量有些古怪,即它们以value = 0创建,这意味着已锁定(或保留,已获得),而不是value = 1(表示 free (或 available ))。可以使用一个简单的技巧来解决此问题,例如示例程序:http://lzsiga.users.sourceforge.net/sysv_sem_test.c