Advertisement
majczel23000

[SO] 28.11.2017 - semafor.h

Nov 28th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.47 KB | None | 0 0
  1. int key;
  2.  
  3. int semCreate(int key){
  4.  
  5.     return semget(key,1, IPC_CREAT|0600);
  6.  
  7. }
  8.  
  9. void semInit(int semId){
  10.  
  11.     semctl(semId,0,SETVAL,1);
  12.  
  13. }
  14.  
  15. void semRemove(int semId){
  16.  
  17.     semctl(semId,0,IPC_RMID);
  18.  
  19. }
  20.  
  21. void semDown(int semId){
  22.  
  23.     struct sembuf buf={.sem_num=0, .sem_op=-1, .sem_flg=0};
  24.  
  25.     semop(semId,&buf,1);
  26.  
  27. };
  28.  
  29. void semUp(int semId){
  30.  
  31.     struct sembuf buf={.sem_num=0, .sem_op=1, .sem_flg=0};
  32.  
  33.     semop(semId,&buf,1);
  34.  
  35. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement