【问题标题】:semop failed invalid argument aix 7.1semop 失败的无效参数 aix 7.1
【发布时间】: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 创建信号量,并在同步完成后删除信号量。但是过了一会儿,即使我们没有任何错误地创建新的信号量,信号量操作也会失败,参数无效
  • 好吧,那你知道原因是什么了:另一个线程/进程破坏了信号量。

标签: semaphore aix


【解决方案1】:

正如我已经在评论中写的那样,您的另一个线程/进程已删除您尝试使用的信号量。您不应该在每次使用时都创建和销毁信号量。

Off:我承认 SYSV 信号量有一个小怪癖,即它们是用 value=0 创建的,这意味着 locked(或 reservedacquired em>),而不是 value=1(意思是 free(或 available))。这可以通过一个简单的技巧来解决,示例程序:http://lzsiga.users.sourceforge.net/sysv_sem_test.c

【讨论】:

    猜你喜欢
    • 2020-12-22
    • 2012-11-21
    • 2019-06-09
    • 1970-01-01
    • 2020-09-16
    • 2021-09-22
    • 2010-12-09
    • 2014-12-31
    • 1970-01-01
    相关资源
    最近更新 更多