Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pthread_yield and sched_yield

2,344 views
Skip to first unread message

TC Shen

unread,
Oct 2, 2001, 1:26:31 PM10/2/01
to
Hello there:
I checked the Thread FAQ and pthread_yield() is not in POSIX standard
anymore and FAQ suggests us to use sched_yield() instead. Then, I
checked man pages for HPUX11i and SunOS.

HPUX man page
sched_yield: requeue current process in process list.
the sched_yield() function forces the running PROCESS to relinquish
the processor .........


SunOS 5.7 man page:
The sched_yield() function forces the running THREAD to relinquish the
processor ...


My questions:
1.Since sched_yield() is a POSIX standard function then why it has two
different interpretations on HPUX 11 and SunOS. How about sched_yield()
on AIX or Linux platforms? Do they relinquish PROCESS or THREAD from
CPU?

2. Since HPUX already supports kernel threads, and its scheduling unit
is thread instead of process, then what a PROCESS means in HPUX? A
process should be a _global_ data structure shared by its threads, it is
not an executing unit anymore, right?

thank you


tcs

Jens-Uwe Mager

unread,
Oct 2, 2001, 4:17:30 PM10/2/01
to
On Tue, 02 Oct 2001 10:26:31 -0700, TC Shen <teche...@yahoo.com> wrote:
>Hello there:
> I checked the Thread FAQ and pthread_yield() is not in POSIX standard
>anymore and FAQ suggests us to use sched_yield() instead. Then, I
>checked man pages for HPUX11i and SunOS.
>
> HPUX man page
> sched_yield: requeue current process in process list.
> the sched_yield() function forces the running PROCESS to relinquish
>the processor .........
>
>
> SunOS 5.7 man page:
> The sched_yield() function forces the running THREAD to relinquish the
>processor ...
>
>
> My questions:
> 1.Since sched_yield() is a POSIX standard function then why it has two
>different interpretations on HPUX 11 and SunOS. How about sched_yield()
>on AIX or Linux platforms? Do they relinquish PROCESS or THREAD from
>CPU?

AIX also says the current THREAD is scheduled. As threads in Linux are
just processes I would say it does not matter on Linux.

> 2. Since HPUX already supports kernel threads, and its scheduling unit
>is thread instead of process, then what a PROCESS means in HPUX? A
>process should be a _global_ data structure shared by its threads, it is
>not an executing unit anymore, right?

May be they forgot to update their man page?


--
"I just opitimzed that algorithm 10x, it gets to the segfault much
faster now!" -- anonymous
Jens-Uwe Mager <pgp-mailto:62CFDB25>

David Butenhof

unread,
Oct 3, 2001, 8:40:33 AM10/3/01
to
TC Shen wrote:

> I checked the Thread FAQ and pthread_yield() is not in POSIX standard
> anymore and FAQ suggests us to use sched_yield() instead. Then, I
> checked man pages for HPUX11i and SunOS.

The realtime (1003.1b) and thread (1003.1c) amendments to POSIX were
developed by the same working group, but more or less independently. In
particular, we didn't know for sure in what order they'd become approved
standards and integrate with the base 1003.1 standard.

During the final stages of 1003.1c review, however, and long after 1003.1b
had been approved and integrated, we spent some time searching through the
standard for phrases that needed to be changed to address threads. For
example, finding places where we said "process" but, for threads, it should
now say "thread". The description of sched_yield(), of course, was one such
place.

And after it had been fixed, some observant person noticed that the
descriptions of sched_yield() and pthread_yield() were now identical. Since
sched_yield() was already in the standard, it was silly to add
pthread_yield() to do exactly the same thing, and pthread_yield() was
removed from the standard.

> HPUX man page
> sched_yield: requeue current process in process list.
> the sched_yield() function forces the running PROCESS to relinquish
> the processor .........

For HP-UX 10.30 and later, this is plain wrong. I'm willing to assume it's
a bug in the manpage rather than a bug in the implementation. In a kernel
that schedules threads, such operations "on a process" are nearly
impossible, and certainly don't happen without a strong and consistent
INTENT by the developers... which would be pointless.

> SunOS 5.7 man page:
> The sched_yield() function forces the running THREAD to relinquish the
> processor ...

This is correct, more or less. Although the word "forces" isn't quite
accurate. THAT depends on what else is available to run on the processor.
For example, if there are no other threads at the same or higher priority,
the caller will continue running. Rather, it should say that the call
"forces the thread to consider whether to relinquish the processor".

> My questions:
> 1.Since sched_yield() is a POSIX standard function then why it has two
> different interpretations on HPUX 11 and SunOS. How about sched_yield()
> on AIX or Linux platforms? Do they relinquish PROCESS or THREAD from
> CPU?

Since sched_yield() is a POSIX standard function, it MUST be a "thread
yield" rather than a "process yield" on all implementations that support
threads. Otherwise the implementation is erroneous. Most likely HP-UX 11 is
correct and only the manpage is wrong, but you should report the problem to
them anyway so they can fix whatever needs to be fixed.

> 2. Since HPUX already supports kernel threads, and its scheduling unit
> is thread instead of process, then what a PROCESS means in HPUX? A
> process should be a _global_ data structure shared by its threads, it is
> not an executing unit anymore, right?

Correct. Of course, the kernel implementation of sched_yield() COULD, if an
implementor was sufficiently determined and foolish, iterate through all
threads in the process and cause them ALL to yield. I sure HOPE nobody
would be ignorant enough to do that, but I guess you never know.

/------------------[ David.B...@compaq.com ]------------------\
| Compaq Computer Corporation POSIX Thread Architect |
| My book: http://www.awl.com/cseng/titles/0-201-63392-2/ |
\-----[ http://home.earthlink.net/~anneart/family/dave.html ]-----/

Vasudevan Sangili

unread,
Oct 3, 2001, 8:57:18 PM10/3/01
to
David Butenhof wrote:

> > HPUX man page
> > sched_yield: requeue current process in process list.
> > the sched_yield() function forces the running PROCESS to relinquish
> > the processor .........
>
> For HP-UX 10.30 and later, this is plain wrong. I'm willing to assume it's
> a bug in the manpage rather than a bug in the implementation. In a kernel
> that schedules threads, such operations "on a process" are nearly
> impossible, and certainly don't happen without a strong and consistent
> INTENT by the developers... which would be pointless.
>

The man page needs to be corrected. sched_yield() operation is indeed
performed on the 'thread' level and not the process level.

--Vasu

0 new messages