Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
21364a7251f7f7af4faf7a557fa2714a87b85a68
[simgrid.git] / src / java / simgrid / msg / Sem.java
1 package simgrid.msg;\r
2 \r
3 public class Sem { \r
4         private int permits_;\r
5         \r
6         public Sem(int i) {\r
7                 permits_ = i;\r
8         }\r
9         \r
10         public void acquire() throws InterruptedException {\r
11                 \r
12                 if (Thread.interrupted()) \r
13                         throw new InterruptedException();\r
14                 \r
15                 synchronized(this) {\r
16                 \r
17                         try {\r
18                                         while (permits_ <= 0) \r
19                                                 wait();\r
20                                         \r
21                                         --permits_;\r
22                         }\r
23                         catch (InterruptedException ex) {\r
24                                 notify();\r
25                                 throw ex;\r
26                         }\r
27                 }\r
28         }\r
29 \r
30         public synchronized void release() {\r
31                 ++(this.permits_);\r
32                 notify();\r
33         }\r
34 }\r