[Python-Dev] POSIX thread code (original) (raw)

Martin v. Loewis martin@v.loewis.de
28 Feb 2002 08:57:32 +0100


"Tim Peters" <tim@zope.com> writes:

Semaphores weren't defined by POSIX at the time this code was written; IIRC, they were first introduced in the later and then-rarely implemented POSIX realtime extensions. How stable are they?

They are in Single UNIX V2 (1997), so anybody claiming conformance to Single UNIX has implemented them:

In addition, the following implementations document support for sem_init:

> According to POSIX, they are found in <semaphore.h> and > POSIXSEMAPHORES should be defined if they work as POSIX > expects.

This may be a nightmare; for example, I don't see anything in the Single UNIX Specification about this symbol, and as far as I'm concerned POSIX as a distinct standard is a DSW (dead standard walking ). That's one for the Unixish geeks to address.

You didn't ask google for _POSIX_SEMAPHORES, right? The first hit brings you to

http://www.opengroup.org/onlinepubs/7908799/xsh/feature.html

_POSIX_SEMAPHORES Implementation supports the Semaphores option.

A quick check shows that both Solaris 8 and glibc 2.2 do indeed define the symbol.

They could be hugely better on Linux, but I don't know: there's anecdotal evidence that Linux scheduling of threads competing for a mutex can get itself into a vastly unfair state.

For glibc 2.1, semaphores have been reimplemented; they now provide FIFO wakeup (sorted by thread priority). Same for mutexes: the highest-priority oldest-waiting thread will be resumed.

do { ... call the right one ... } while (status < 0 && errno == EINTR);

Shouldn't EINTR check for KeyboardInterrupt?

Regards, Martin