由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Semaphores in Linux (转载)
相关主题
大家看过来Re: C++ Guys!!!!thread, semaphore, 问题。
boost的deadline_timer要多脑残才能整出来?Restaurant Reservation System...
多个thread的通信about critical section
请问这些问题应该在那种书上找到答案?关于multi thread
Multi-thread可以mutex锁资源,Multi-process怎么锁资源?how to answer this question, thanks
给大家出个多进程的题mutex和semaphore的差别到底是什么?
为什么说semaphore是一种进程间的通信方式。谁能推荐一个read-writer lock的C++实现? (转载)
INIT_WORK从Linux kernel 2.6.20后改了?你们觉得《the little book of semaphore》这本书怎么样?
相关话题的讨论汇总
话题: linux话题: semaphores话题: system话题: posix话题: use
进入Programming版参与讨论
1 (共1页)
n**d
发帖数: 9764
1
【 以下文字转载自 Linux 讨论区 】
发信人: noid (DoIneedit?), 信区: Linux
标 题: Semaphores in Linux
发信站: BBS 未名空间站 (Sat Jan 10 00:14:53 2009)
http://www.linuxdevcenter.com/pub/a/linux/2007/05/24/semaphores-in-linux.html?page=1
in this link, the author says "In general, the older Unix-based systems uses
the System V version and the current Linux-based systems use the POSIX
version."
The System V uses semget()... and POSIX uses sem_init...
However, in my company's Linux system, the gcc compiles semget()...
succesfu
T*****9
发帖数: 2484
2
头文件不一样

uses

【在 n**d 的大作中提到】
: 【 以下文字转载自 Linux 讨论区 】
: 发信人: noid (DoIneedit?), 信区: Linux
: 标 题: Semaphores in Linux
: 发信站: BBS 未名空间站 (Sat Jan 10 00:14:53 2009)
: http://www.linuxdevcenter.com/pub/a/linux/2007/05/24/semaphores-in-linux.html?page=1
: in this link, the author says "In general, the older Unix-based systems uses
: the System V version and the current Linux-based systems use the POSIX
: version."
: The System V uses semget()... and POSIX uses sem_init...
: However, in my company's Linux system, the gcc compiles semget()...

n**d
发帖数: 9764
3
I know the differnce between System V and POSIX for Semaphore. My question
is what kind of Semaphore Linux supports, System V or POSIX.

【在 T*****9 的大作中提到】
: 头文件不一样
:
: uses

T*****9
发帖数: 2484
4
try to use the -lphread option when you compiler with gcc

【在 n**d 的大作中提到】
: I know the differnce between System V and POSIX for Semaphore. My question
: is what kind of Semaphore Linux supports, System V or POSIX.

n**d
发帖数: 9764
5
Yes, we can use gcc with -lrt or -lpthread to pass compile and link. What
does it mean? So can we say Linux supports both kinds of Semaphores?

【在 T*****9 的大作中提到】
: try to use the -lphread option when you compiler with gcc
r*********r
发帖数: 3195
6
不奇怪. 可能两种都支持. Sys V 的强大, 但难用.
Posix 语义更清楚. 经常是 posix 的用 sys v 来实现, 本身只是一个wrapper.
但是 posix 又分两种, 有名的是 sem_open, 无名是 sem_init.
有可能系统只支持 sem_open, 因为 sem_init 只能用于线程, 不能用作 ipc.
n**d
发帖数: 9764
7
How do we use System V Semaphores for unrelated processes (not forked one)?
Some example code uses Ftok("filename" ...) to generate the key. So if the 2
processes use the same filename then they can get the same key.
More often, we use IPC_PRIVATE for the key. In this case, how can the 2
processes get the same key? Does that mean we have to use Ftok() if we want
to use Sys V Semaphores for 2 unrelated processes?

【在 r*********r 的大作中提到】
: 不奇怪. 可能两种都支持. Sys V 的强大, 但难用.
: Posix 语义更清楚. 经常是 posix 的用 sys v 来实现, 本身只是一个wrapper.
: 但是 posix 又分两种, 有名的是 sem_open, 无名是 sem_init.
: 有可能系统只支持 sem_open, 因为 sem_init 只能用于线程, 不能用作 ipc.

r*********r
发帖数: 3195
8
用 IPC_PRIVATE 就不能 share.
n**d
发帖数: 9764
9
Besides Ftok(), is there any other way?

【在 r*********r 的大作中提到】
: 用 IPC_PRIVATE 就不能 share.
r*********r
发帖数: 3195
10
如果你已经通过其它方法拿到了 key (比如 ipcs), 就不需要 ftok.
1 (共1页)
进入Programming版参与讨论
相关主题
你们觉得《the little book of semaphore》这本书怎么样?Multi-thread可以mutex锁资源,Multi-process怎么锁资源?
critical section semaphore muta的问题给大家出个多进程的题
multi-thread 一问,为什么说semaphore是一种进程间的通信方式。
精华区翻出来的MS老题,thread safeINIT_WORK从Linux kernel 2.6.20后改了?
大家看过来Re: C++ Guys!!!!thread, semaphore, 问题。
boost的deadline_timer要多脑残才能整出来?Restaurant Reservation System...
多个thread的通信about critical section
请问这些问题应该在那种书上找到答案?关于multi thread
相关话题的讨论汇总
话题: linux话题: semaphores话题: system话题: posix话题: use