RE: Pthread performance

David Schwartz (
Sun, 13 Jul 2003 13:11:44 -0700

> I found a benchmark program for threads and found a major
> difference between a single CPU and dual CPU system.
> Here's the code:
> Is this showing context switches going between CPUs??


> Wouldn't one expect the dual CPU to run twice as fast instead of
> ten times slower?

Not necessarily. The code doesn't do much other than modified shared data
without a lock. Not only does this invoke undefined behavior, but it
penalizes SMP machines because only they are subject to cache ping-ponging.

> As you can see from the timing user time increases by a factor of
> 4 and system time by a factor of 10.
> I seem to remember something about gettimeofday() possibly being
> a problem but couldn't find a reference to it.
> Anybody have an explanation/fix for this?

The program doesn't seem to measure anything useful and invokes undefined

If you would like a fix, try this:

#define sched_yield() while(false)


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at