当前位置: 技术问答>linux和unix
问个信号量问题
来源: 互联网 发布时间:2016-04-11
本文导语: 请问LInux的进程和线程间的信号量机制的函数能否通用? 特别是线程同步的一些信号量函数,进程能否使用呢?用起来会不会有问题? | Linux各信号量对于进程和线程都有统一接口,例如Posix...
请问LInux的进程和线程间的信号量机制的函数能否通用?
特别是线程同步的一些信号量函数,进程能否使用呢?用起来会不会有问题?
特别是线程同步的一些信号量函数,进程能否使用呢?用起来会不会有问题?
|
Linux各信号量对于进程和线程都有统一接口,例如Posix基于内存的信号量在初始化时调用sem_init(sem_t *sem, int pshared, unsigned value),第二个参数pshared为零表示线程间,非零则为进程间,其它类似,参考下UNPV2:
A semaphore is a primitive used to provide synchronization between various processes or between the various threads in a given process. We look at three types of semaphores in this text.
1 Posix named semaphores are identified by Posix IPC names (Section 2.2) and can be used to synchronize processes or threads.
2 Posix memory-based semaphores are stored in shared memory and can be used to synchronize processes or threads.
3 System V semaphores (Chapter 11) are maintained in the kernel and can be used to synchronize processes or threads.
A semaphore is a primitive used to provide synchronization between various processes or between the various threads in a given process. We look at three types of semaphores in this text.
1 Posix named semaphores are identified by Posix IPC names (Section 2.2) and can be used to synchronize processes or threads.
2 Posix memory-based semaphores are stored in shared memory and can be used to synchronize processes or threads.
3 System V semaphores (Chapter 11) are maintained in the kernel and can be used to synchronize processes or threads.