Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import java.util.concurrent.Semaphore;
  2.  
  3. import org.omg.PortableServer.POAManagerPackage.State;
  4.  
  5.  
  6. public class Ispit {
  7.  
  8.  
  9. static Semaphore teacher;
  10. static Semaphore studenti;
  11. static Semaphore lock;
  12. static int br;
  13. static Semaphore ready;
  14. static Semaphore readyToLeave;
  15. static Semaphore done;
  16.  
  17. public static void init()
  18. {
  19. teacher = new Semaphore(1);
  20. lock = new Semaphore(1);
  21. studenti = new Semaphore(0);
  22. br=0;
  23. ready = new Semaphore(0);
  24. readyToLeave = new Semaphore(0);
  25. done = new Semaphore(0);
  26. }
  27. public static void Teacher() throws InterruptedException
  28. {
  29. teacher.acquire();
  30. state.teacherEnter();
  31. studenti.release(50);
  32. ready.acquire();
  33. state.distirbuteTests();
  34. state.endExam();
  35.  
  36. readyToLeave.release(50);
  37. done.acquire();
  38.  
  39. teacher.release();
  40.  
  41. }
  42. public static void Student() throws InterruptedException
  43. {
  44.  
  45. studenti.acquire();
  46. state.studentEnter();
  47.  
  48. lock.acquire();
  49. br++;
  50. lock.release();
  51.  
  52. if(br==50)
  53. ready.release(); //ako vlegle tocno 50
  54.  
  55. readyToLeave.acquire();
  56. state.studentLeave();
  57.  
  58. lock.acquire();
  59. br--;
  60. lock.release();
  61.  
  62. if(br==0)
  63. done.release();
  64.  
  65.  
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement