You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Selfex.java 778B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package coordination;
  2. import java.lang.String;
  3. class Selfex implements Exclusion {
  4. String methodName;
  5. Thread thread;
  6. int count = 0;
  7. Selfex (String _methodName) {
  8. methodName = _methodName;
  9. }
  10. public boolean testExclusion (String _methodName) {
  11. if (count == 0)
  12. return(true);
  13. return (thread == Thread.currentThread());
  14. }
  15. public void enterExclusion (String _methodName) {
  16. count++;
  17. thread = Thread.currentThread(); // note that if count wasn't 0
  18. // we aren't changing thread
  19. }
  20. public void exitExclusion (String _methodName) {
  21. count--;
  22. if (count == 0) // not stricly necessary, but...
  23. thread = null;
  24. }
  25. public void printNames() {
  26. System.out.println("Selfex name: " + methodName);
  27. }
  28. }