Re: [Fwd: Possible bug in Thread.start()]

Chris Pickett <[email protected]>
Newsgroups gmane.comp.java.vm.sablevm.devel
Message-ID <[email protected]>
Archie Cobbs wrote:
> Chris Pickett wrote:
> 
>> Etienne Gagnon wrote:
>>
>>> -------- Original Message --------
>>> Subject: Possible bug in Thread.start()
>>> Date: Mon, 13 Dec 2004 17:38:47 -0600
>>> From: Archie Cobbs <[email protected]>
>>> To: old mailing-list
>>>
>>> Hello Sablevm folks,
>>>
>>> I recently discovered a bug in JC that may also apply to SableVM,
>>> because JC's thread handling is based on SableVM.
>>>
>>> The bug is a race condition between thread #1 stopping the world
>>> and thread #2 creating a new thread via Thread.start().
>>
>>
>> Thanks Archie, I've chased bugs related to thread startup in the GC 
>> stuff before (threads will reach the "impossible control flow" case), 
>> but never managed to nail it.
> 
> 
> Well hopefully this is it. By the way, here is the test program
> that I was using to trigger the bug in JC. Maybe you can try it
> with SableVM "before and after" the bug fix.

I tried your test program, but it didn't crash SableVM, either before or 
after the patch.  I had to hit CTRL-C to stop it, but I think that was 
intentional.

It does however fix crashing in the attached program, which is great.  I 
ran this program 100 times with:

$ for num in `seq 1 100`; do sablevm -Y ThreadStarter; done

and without your patch it would segfault one or two times in 100.

Cheers,
Chris

_______________________________________________
SableVM-devel mailing list
[email protected]
http://sablevm.org/lists/control/listinfo/sablevm-devel
ThreadStarter.java (text/x-java, 988 B)
/* attempts two different ways to start threads.
   
   note that none of:

     a) way 1; way 1;
     b) way 2; way 2;
     c) way 2; way 1;
 
   were observed to fail, with 100+ runs, whereas

     d) way 1; way 2;

   fails about 5 percent of the time on
   tofu.cs.mcgill.ca (2P).

   (if you make things more complex by adding another
    Runnable implementation, it fails more often, but
    this was the most stripped down I could get it)
*/

public class ThreadStarter {
    
    public ThreadStarter() {
    }    
    
    public static void main(String[] argv) {
	
	Runnable myRunnable;
	Thread myThread;  

	/* way 1 */
	myRunnable = new IncrementRunnable();
	myThread = new Thread(myRunnable);
	myThread.start();

	/* way 2 */
	myRunnable = new IncrementRunnable();
	myRunnable.run();
    }
}

class IncrementRunnable implements Runnable {

    private int k = 0;

    public IncrementRunnable() {
    }

    public void run() {
	for(int i=0;i<100;i++) {
	    k++;
	}
    }
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.