This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Bug in threading gcj/minGW
- From: "Erik Poupaert" <erik dot poupaert at chello dot be>
- To: <java at gcc dot gnu dot org>
- Date: Tue, 7 Jan 2003 12:06:07 +0100
- Subject: Bug in threading gcj/minGW
Hi
I've made a little test case that illustrates the SWT/FileViewer.java bug,
by extracting the relevant sections out of the example. To simplify the
case, I have not used SWT to obtain user input, but System.in. The idea is
that the user releases the worker thread by pressing a key.
I've made the testcase as small and simple as possible.
You can clearly observe that the version compiled with javac behaves
differently from the version compiled with gcj. The version compiled with
gcj will wait only one time, and then never wait again.
Does the problem also occur with posix-threads (linux,...)?
Can anybody repeat this test and confirm that it is a bug?
I'll make sure to add it into the gcj bugzilla thing, if it can be
confirmed.
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
public class TestThreading
{
private final Object mWorkerLock = new Object();
private volatile Thread mWorkerThread = null;
protected boolean mWorkerStopped=false;
private final Runnable mWorkerRunnable = new Runnable() {
public void run() {
while (!mWorkerStopped) {
synchronized(mWorkerLock) {
}
synchronized(mWorkerLock) {
try {
System.out.println("worker waiting");
//the thread must wait here until notification of the lock !!!
mWorkerLock.wait();
System.out.println("worker wait is over ");
} catch (InterruptedException e) {
}
}
}
System.out.println("killing thread");
mWorkerThread = null;
}
};
public static void main(String args[]) throws IOException
{
TestThreading t=new TestThreading();
}
public TestThreading() throws IOException
{
BufferedReader reader=new BufferedReader(new
InputStreamReader(System.in));
while(!mWorkerStopped)
{
System.out.print("press enter (or s to stop)");
int c=0;
try
{
c=(reader.readLine()).charAt(0);
}
catch(Exception e) {}
System.out.print("\n");
if((char)c=='s')
{
System.out.println("stopping worker");
mWorkerStopped=true;
synchronized(mWorkerLock) { mWorkerLock.notifyAll(); }
}
else
{
workerUpdate();
}
}
}
private void workerUpdate() {
synchronized(mWorkerLock)
{
mWorkerStopped = false;
System.out.println("worker update - notify All");
mWorkerLock.notifyAll();
}
if (mWorkerThread == null) {
mWorkerThread = new Thread(mWorkerRunnable);
System.out.println("worker update - thread start");
mWorkerThread.start();
}
}
}