Skip to content

Instantly share code, notes, and snippets.

@bayerj
Created December 10, 2009 09:25
Show Gist options
  • Select an option

  • Save bayerj/253235 to your computer and use it in GitHub Desktop.

Select an option

Save bayerj/253235 to your computer and use it in GitHub Desktop.
public class Semaphore {
private int count;
public Semaphore(int count) {
this.count = count;
}
public synchronized void p() {
count--;
while (count < 0) {
try {
this.wait();
} catch(Exception e) {
e.printStackTrace();
}
}
}
public synchronized void v() {
count++;
if (count <= 0) {
this.notify();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment