[kaffe] Bug Report
Paul M Hounslow
Paul.Hounslow at dctl.com
Wed Apr 24 07:44:24 PDT 2002
Hi,
I have possible bug report with threading and nested locks.
When two threads are nested on the same lock and one (or both) of
them sleeps inside the nest, an IllegalMonitorStateException will be
thrown. The lock in question is allocated as a fast lock, however,
when the sleep method is called it enters the slow lock code, and
gets corrupted.
A simple test program is included below
This program works under Java(TM) 2 Runtime Environment, Standard
Edition (build 1.3.1-b24), Java HotSpot(TM) Client VM (build 1.3.1-
b24, mixed mode).
It fails under kaffe-1.0.6.
-----------------------------Program start---------------------------
/***************************************************************
COPYRIGHT NOTICE
This file remains the intellectual property of:
DCT Limited
www.dctl.com
Unit 5, Windmill Business Village
Brooklands Close
Sunbury-Upon-Thames, TW19 7DY
All rights reserved. Copyright DCT Limited: 2002
***************************************************************/
public class NestedLocks {
public LockObj lock = new LockObj();
public NestedLocks() {
new SecondThread().start();
synchronized(lock) {
debug("(1) Got lock: " + lock);
synchronized(lock) {
debug("(2) Got lock: " + lock);
try {
Thread.sleep(500);
} catch (InterruptedException ie) {
debug("Sleep interrupted: "+ie);
}
debug("Slept for 500 ms");
}
debug("(2) Released lock");
}
debug("(1) Released lock");
}
public void debug(String s) {
System.out.println(s);
}
public static void main(String [] args) {
new NestedLocks();
}
/********* SECOND THREAD **********/
class SecondThread extends Thread {
public void run() {
synchronized(lock) {
debug("T2:(1) Got lock: " + lock);
try {
Thread.sleep(500);
} catch (InterruptedException ie) {
debug("Sleep interrupted: "+ie);
}
debug("Slept for 500 ms");
}
debug("T2:(1) Released lock");
}
}
}
class LockObj {
static int count = 0;
int id;
public LockObj() {
id = count++;
}
public String toString() {
return ("LOCK#"+id);
}
}
---------------------------------------------------------------------
--
Paul Hounslow DCT Limited
Email: Paul.Hounslow at dctl.com
Tel: +44 1932 766515
Fax: +44 1932 782811
Web: http://www.dctl.com/
More information about the kaffe
mailing list