[concurrency-interest] Multi-core testing, help with findings

Gregg Wonderly gregg at cytetech.com
Mon Dec 11 22:12:46 EST 2006



David Holmes wrote:
> I've assumed the platform is Windows, but if it is linux then that opens
> other possibilities. The problem can be explained if the busy-wait thread
> doesn't get descheduled (which is easy to test by changing it to not be a
> busy-wait). The issue as to why it doesn't get descheduled is then the
> interesting part. I suspect an OS scheduling quirk on multi-core, but need
> more information.

>>>>>    private long doIt() {
>>>>>        long startTime = System.currentTimeMillis();
>>>>>        for(int i = 0; i < howMany; i++) {
>>>>>            new Thread(new Worker()).start();
>>>>>        }
>>>>>        while(!finished);
>>>>>        long endTime = System.currentTimeMillis();
>>>>>        return (endTime - startTime);
>>>>>
>>>>>    }

Historically, I've found that busy waits like the above are problematic.  I'd go 
along with David's comment/thought and try

	while(!finished) Thread.yield();

or something else to cause it to get descheduled for a whole quanta for each 
check rather than busy waiting for a whole quanta which will keep at least one 
CPU busy doing nothing productive.

Gregg Wonderly


More information about the Concurrency-interest mailing list