#include
#include
#include
#include
#include
union semun{
int val;
unsigned short *array;
};
int main()
{
struct sembuf down={0,-1,IPC_NOWAIT};
struct sembuf up={0,1,IPC_NOWAIT};
int semid;
union semun arg;
unsigned short array[100]={0};
arg.val=1;
arg.array=array;
int a,b;
//建立信号量
semid=semget(123,1,IPC_CREAT|0666);
if(semid<0)
{
perror("semaphore created faluse.");
}
//设置信号量
a=semctl(semid,0,SETVAL,arg);
if(a<0)
perror("semctl faluse.");
//操作信号量
b=semop(semid,&down,1);//lock
if(b<0)
{perror("lock faluse");}
else
{
printf("this is a test.\n");
sleep(10);
}
semop(semid,&up,1);//unlock
return 0;
}
这段代码 哪里出错了??我调不出来