Python threading (was: Re: global interpreter lock not working as it should)

Martin v. Loewis martin at
Tue Aug 6 10:44:35 CEST 2002

bokr at (Bengt Richter) writes:

> >POSIX specifies that pthread_cond_wait can return spontaneously, which
> When my computer acts "spontaneous" I worry ;-) What kinds of spontaneity
> are anticipated?

I think no rationale is given; it probably simplifies the
implementation on some systems. For example, it could be that threads
get a SIGUSR1, which happens to be used as a wakeup signal in an
implementation. People are usually at a loss explaining this aspect of
POSIX - yet it is documented everywhere.

> Yes, some kind of reference implementation to look at. I thought Linux
> would be a good candidate. I guess it's expected to be part of glibc2
> though, so it would just be extracted for a reference.

This is the first time that this subject came up (atleast at that
level of detail, atleast AFAIR); anybody who wants to research the
details should know where to search. They should also know that
linuxthreads most likely is *not* a typical representative of these
things, since Linus refuses to support threads in the OS kernel (as
opposed to merely supporting processes); until very recently.

> BTW, is there a Python module that can unpack rpms?

I think the standard rpm distribution comes with Python modules, since
Redhat does much of their RPM management in Python.

> Well, I come back to the question of whether and/or when we want to enforce
> handover of the lock, or otherwise modify the way it's held. 

I don't think so: there is no problem to solve here. If every 10 byte
code instructions there was a thread switch, you'd get quite a
performance desaster.

> It would be nice to know what the design intent for the optimum was,
> even if that can't always be achieved.

The intent (as I earlier said) is to
a) to operate similarly on a wide range of systems,
b) minimise the overhead that threading takes, compared to a non-threaded
   application, and
c) provide a minimum amount of fairness, if the underlying system has
   some guarantee of fairness. IOW, starvation should not be observable
   in real life.


More information about the Python-list mailing list