summaryrefslogtreecommitdiff
path: root/libjava/testsuite/libjava.lang/PR27908.java
blob: addb1d7720fc6c9571015b38bc2a5d3fccf9d7e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
class PR27908
{
  public static void main (String[] argv)
    throws InterruptedException
  {
    run1 r1 = new run1();
    run2 r2 = new run2();
    run3 r3 = new run3();

    Thread t1, t2, t3;

    (t1 = new Thread (r1)).start();
    (t2 = new Thread (r2)).start();
    (t3 = new Thread (r3)).start();

    while (! (r1.isRunning() && r2.isRunning() && r3.isRunning()))
      Thread.yield();

    r1.stop();
    r2.stop();
    r3.stop();

    Thread.sleep(5000);

    if (t1.isAlive() || t2.isAlive() || t3.isAlive())
      {
	System.out.println ("fail");
	System.exit(1);
      }
  }

  private static class run1 implements Runnable
  {
    volatile int counter;
    volatile boolean running;

    public void run ()
    {
      counter = 0;
      running = true;
      while (running)
        counter++;
    }

    void stop ()
    {
      running = false;
    }

    public boolean isRunning()
    {
      return running;
    }
  }

  private static class run2 implements Runnable
  {
    volatile int counter;
    boolean running;

    public void run ()
    {
      counter = 0;
      running = true;
      while (running)
        counter++;
    }

    void stop ()
    {
      running = false;
    }

    public boolean isRunning()
    {
      return running;
    }
  }

  static class run3 implements Runnable
  {
    volatile int counter;
    private volatile boolean running;

    public void run ()
    {
      counter = 0;
      running = true;
      while (running)
        counter++;
    }

    void stop ()
    {
      running = false;
    }

    public boolean isRunning()
    {
      return running;
    }
  }
}