[concurrency-interest] interrupt / notify races even in 6.0 beta?

Holger Hoffstätte holger at wizards.de
Tue May 16 04:02:44 EDT 2006


Dawid,

I extended the test to collect results for multiple runs. I then ran this
for longer periods and got some more interesting results.
	
1) Linux version 2.6.16.9 (Gentoo), no preemptible scheduler or other toys
configured ('vanilla' as it can get), glibc 2.4 and Sun JDKs 1.4.2.11,
1.5.0.06 and Mustang b82 consistently gives A-A (i.e. 'wrong' behaviour)
every time, regardless how many samples I run.

2) Windows XP SP1, Sun JDK 1.4.2.09, 1.5.0.06 and Mustang b82 relatively
consistently give I-A with the occasional A-A. Multipe test runs are
necessary to observe this; in other words it happens on Windows too.

The modified test is attached.

Holger
-------------- next part --------------

import java.util.List;
import java.util.ArrayList;

public class Test extends Thread {

	public static int NUM = 10;
	public static int SLEEP = 100;
	public static List values = new ArrayList();

	public static volatile char s;

    final static Object lock = new Object();

    public void run() {
        try {
            synchronized (lock) { lock.wait(); }
            s = 'A';
        } catch (InterruptedException e) {
        	s = 'I';
        }
    }

    public static void main(String[] args) throws Exception {
    
		for (int i = 0; i < NUM; i++)
		{
			Thread t;
			t = new Test();
			t.start();
			Thread.sleep(SLEEP);
			t.interrupt();
			synchronized (lock) { lock.notify(); }
			t.join();
			char s1 = s;

			t = new Test();
			t.start();
			Thread.sleep(SLEEP);
			synchronized (lock) { lock.notify(); }
			t.interrupt();
			t.join();
			char s2 = s;

			values.add(new String(new char[]{s1, s2}));

			Thread.sleep(SLEEP*2);
		}

		System.out.println(values);
    }
}



More information about the Concurrency-interest mailing list