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

From: Mohit Aron (
Date: Mon Feb 05 2001 - 02:27:35 EST

Thanks for a reasonable/thoughtful reply.

> to expect perfect alternation is not reasonable. the scheduler
> (or one of its subsidiary and/or supporting functions) decides what
> should run and what shouldn't. the linux scheduler did have problems
> in 2.2 (and still does in some places). however last i checked
> sched_yield() is at best a hint to the scheduler not a command. the
> man page even suggests this. it says that if the process (or thread)
> yields and if it is the highest priority task at the time it will be
> re-run. so you can not guarantee that it will not re-run. this i think
> was the point david was trying to make (albiet with some possibly
> misplaced "fervour").

It looks like what you're saying above is that the scheduling
priority of a thread might be changed dynamically by the scheduler.
Hence, even though it called sched_yield(), its resulting priority might
still be higher than the other thread and hence there may not be
perfect alternation. This makes sense.

However, I just had a chance to run my program on a Linux 2.4 kernel.
I got almost perfect alternation every time I ran it. The output was:


Basically, the first thread prints twice in the beginning but after
that there's perfect alternation. This might however be because of
startup delays in Thread2.

I might add that I've tested my program on two other operating systems -
Solaris 2.7 and DUNIX V4.0D. In both I got perfect alternation every
time I ran the program. And with Linux 2.4 there was "almost" perfect

- Mohit
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