Advertisement
WladcaTejKrainy

Untitled

Dec 5th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. binarysem semafor1;
  2. binarysem semafor2;
  3.  
  4. int liczba=0;
  5.  
  6. void producent(){
  7.     int i;
  8.     wait(semafor1);
  9.     for(i=0;i<10;i++){
  10.         liczba=random(10);
  11.     }
  12.     signal(semafor2);
  13. }
  14.  
  15. void konsumpcjonista(){
  16.     wait(semafor2);
  17.     cout << liczba << endl;
  18.     signal(semafor1);
  19. }
  20.  
  21. main() {
  22. int j;
  23. for(j=0;j<10;j++){
  24.         cobegin  {
  25. initialsem(semafor1,1);
  26. initialsem(semafor2,0);
  27. producent();
  28. konsumpcjonista();
  29. }
  30.         }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement