当前位置: 技术问答>linux和unix
linux 下使用信号量编程的问题·~~~~谁能帮帮我啊????
来源: 互联网 发布时间:2017-01-13
本文导语: 程序如下: #include #include #include #include #include #include #include #include /* union semun { int val; struct semid_ds *buf; unsigned short int *array; struct seminfo *__buf; }; */ int main() { int Semset(int sid,int semnum,int n); int P(int...
程序如下:
#include
#include
#include
#include
#include
#include
#include
#include
/*
union semun
{
int val;
struct semid_ds *buf;
unsigned short int *array;
struct seminfo *__buf;
};
*/
int main()
{
int Semset(int sid,int semnum,int n);
int P(int sid,int semnum,int n);
int V(int sid,int semnum,int n);
int rcounter; //读者数量
int wcounter; //写者数量
pid_t pid;
int i;
int semid;
key_t key;
//union semun arg;
int val;
val=1;
/*创建信号集
0123信号量分别作用如下
sem_t db; //实现写写互斥 ---0
sem_t mutex; //实现读写互斥 ---1
sem_t wc_mutex; //对wcounter实行访问互斥 ---2
sem_t rc_mutex; //rcounter实行访问互斥 ---3
*/
if((key=ftok(".",0))
#include
#include
#include
#include
#include
#include
#include
#include
/*
union semun
{
int val;
struct semid_ds *buf;
unsigned short int *array;
struct seminfo *__buf;
};
*/
int main()
{
int Semset(int sid,int semnum,int n);
int P(int sid,int semnum,int n);
int V(int sid,int semnum,int n);
int rcounter; //读者数量
int wcounter; //写者数量
pid_t pid;
int i;
int semid;
key_t key;
//union semun arg;
int val;
val=1;
/*创建信号集
0123信号量分别作用如下
sem_t db; //实现写写互斥 ---0
sem_t mutex; //实现读写互斥 ---1
sem_t wc_mutex; //对wcounter实行访问互斥 ---2
sem_t rc_mutex; //rcounter实行访问互斥 ---3
*/
if((key=ftok(".",0))