Advertisement
kikosiak

Untitled

Nov 26th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/ipc.h>
  6. #include <sys/shm.h>
  7. #include <sys/sem.h>
  8. #include <signal.h>
  9. #define PERMS 0666
  10.  
  11. static struct sembuf op_lock1[1] = {0, -1, 0};
  12.  
  13. static struct sembuf op_unlock1[1] = {0, 1, 0};
  14.  
  15. static struct sembuf op_lock2[1] = {1, -1, 0};
  16.  
  17. static struct sembuf op_unlock2[1] = {1, 1, 0};
  18.  
  19. void blokuj_semafor1(int semid){
  20.     if (semop(semid, &op_lock1[0], 1)<0)
  21.         perror("blad blokowania semafora");
  22. }
  23.  
  24. void odblokuj_semafor1(int semid){
  25.     if (semop(semid, &op_unlock1[0], 1) < 0)
  26.         perror("blad odlokowania semafora");
  27. }
  28.  
  29. void blokuj_semafor2(int semid){
  30.     if (semop(semid, &op_lock2[0], 1)<0)
  31.         perror("blad blokowania semafora");
  32. }
  33.  
  34. void odblokuj_semafor2(int semid){
  35.     if (semop(semid, &op_unlock2[0], 1) < 0)
  36.         perror("blad odlokowania semafora");
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement