Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. static Semaphore seats;
  2. static Semaphore semph;
  3. static int counter;
  4. static Semaphore playable;
  5. static Semaphore finished;
  6.  
  7.  
  8. public static void init() {
  9. seats = new Semaphore(6);
  10. semph = new Semaphore(1);
  11. counter = 0;
  12. playable = new Semaphore(0);
  13. finished = new Semaphore(0);
  14. }
  15.  
  16. public static class Player extends TemplateThread {
  17.  
  18. public Player(int numRuns) {
  19. super(numRuns);
  20. }
  21.  
  22. @Override
  23. public void execute() throws InterruptedException {
  24. seats.acquire();
  25. state.playerSeat();
  26.  
  27. semph.acquire();
  28. counter++;
  29.  
  30. if(counter==6) {
  31. semph.release();
  32. state.dealCards();
  33. playable.release(5);
  34. state.play();
  35. finished.acquire(5);
  36. counter = 0;
  37. state.endRound();
  38. seats.release(6);
  39. } else {
  40. semph.release();
  41. playable.acquire();
  42. state.play();
  43. finished.release();
  44. }
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement