On Thu, 8 Feb 2001, Joseph Shraibman wrote:

> Is it just me or does Thread.yield() not work anymore with the 2.4.0
> kernel?

Works fine for me (kernel 2.4.1, ibm jdk-1.3 build cx130-20000815). Use the 
attached file for a quick test. 

-- dimitris
   mailto:[EMAIL PROTECTED]
public class test_yield implements Runnable {

    int when_;
    int run_;

    test_yield( int when ) { when_ = when; }
 
    public void run() {
        while( true ) {
            run_++;
            for ( int i = 0; i < when_; i++ );
            Thread.currentThread().yield();
        }
    }
    
    public static void main( String[] args ) {
        int when = args.length > 0 ? Integer.parseInt( args[0] ) : 100000000;
        test_yield t1,t2,t3;
        new Thread( t1 = new test_yield( when ) ).start();
        new Thread( t2 = new test_yield( when ) ).start();
        new Thread( t3 = new test_yield( when ) ).start();
        
        while( true ) try {
            Thread.currentThread().sleep( 1000 );
            int c1 = t1.run_;
            int c2 = t2.run_;
            int c3 = t3.run_;
            System.out.println( "t1: " + c1 + " t2: " + c2 + " t3: " + c3 );
        } catch ( InterruptedException exc ){}

    }

}

Reply via email to