fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.util.Random;
  8.  
  9. /**
  10.  * Example 92 - Mutual Exclusion
  11.  */
  12.  
  13. class Util {
  14. public static void pause(int low, int high) {
  15. Random r = new Random();
  16. int R = r.nextInt(high-low) +low;
  17. try {
  18. Thread.sleep(R);
  19. } catch (InterruptedException e) {
  20. e.printStackTrace();
  21. }
  22. }
  23.  
  24. public static int random(int low, int high) {
  25. Random r = new Random();
  26. int R = r.nextInt(high-low) + low;
  27. return R;
  28. }
  29.  
  30. }
  31. class Printer extends Thread {
  32. static Object mutex = new Object();
  33. public void run() {
  34. for(;;) {
  35. synchronized (mutex) {
  36. System.out.print("-");
  37. Util.pause(100, 300);
  38. System.out.print("/");
  39. }
  40. Util.pause(0, 200);
  41. }
  42. }
  43. }
  44. class MutualExclusion {
  45. public static void main(String[] args) {
  46. new Printer().start();
  47. new Printer().start();
  48. }
  49. }
  50.  
Time limit exceeded #stdin #stdout 5s 28100KB
stdin
Standard input is empty
stdout
-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-