当前位置: 技术问答>linux和unix
信号量的烦恼
来源: 互联网 发布时间:2016-12-28
本文导语: 前几天编了一个有关信号量共享的程序,执行老是通不过!后来在调用semget()和semop()之间添加了一个semctl()才通过,百思不得其解,为什么要调用semctl()呢?是不是创建信号量后必须要调用semctl呢?赐教。 ...
前几天编了一个有关信号量共享的程序,执行老是通不过!后来在调用semget()和semop()之间添加了一个semctl()才通过,百思不得其解,为什么要调用semctl()呢?是不是创建信号量后必须要调用semctl呢?赐教。
|
信号灯创建之后是未初始化的,需要调用semctl自己初始化
The data structure associated with each semaphore in the set is not initialized. The semctl (semctl Subroutine) subroutine (with the Command
parameter values SETVAL or SETALL) can be used to initialize each semaphore.
The data structure associated with each semaphore in the set is not initialized. The semctl (semctl Subroutine) subroutine (with the Command
parameter values SETVAL or SETALL) can be used to initialize each semaphore.
|
的确是这样,你得先初始化各个信号量的初始值,之后才能semop操作。
|
get传1是创建1个信号量,然后ctl是给这个信号量赋初始值。
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。