RE: system call sched_yield() doesn't work on Linux 2.2

From: David Schwartz (
Date: Sun Feb 04 2001 - 19:21:16 EST

> What version of Linux are you using ? What I see is the following:

        I'm using 2.4.1-pre10, glibc 2.1.3.

> Thread1
> Thread1
> Thread1
> Thread1
> Thread1
> Thread2
> Thread2
> Thread2
> Thread2
> Thread2

        That's totally reasonable, although you probably just forgot to fflush.

        It's also possible Thread1 did all its work, yields and all, before Thread2
even got started. Thus Thread1 had no 'ready to run' thread to yield to.
(The main thread may not have been ready to run, it may still have been
waiting to synchronize to the new thread it created.)

> Also, it is NOT unrealistic to expect perfect alternation.

        Find one pthreads expert who agrees with this claim. Post it to
comp.programming.threads and let the guys who created the standard laugh at
you. Scheduling is not a substitute for synchronization, ever.

> The definition
> of sched_yield in the manpage says that sched_yield() puts the
> thread under
> question last in the run queue. So perfect alternation should
> have occurred.

        Your reasoning is totally invalid and ignores so many possible other
factors. For example, who says that the writes that your threads are doing
don't block?

> I've also tested the code on Solaris - there is perfect alternation there.

        I'm not sure I understand what this has to do with anything. If you think
so, then I don't think you appreciate with a standard actually is. Perfect
alternation is reasonable, expecting perfect alternation is not. Probably
the reason you got perfect alternation in Solaris is because you only had
one kernel execution vehicle. Try it with system contention scope threads.


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

This archive was generated by hypermail 2b29 : Wed Feb 07 2001 - 21:00:20 EST