Re: Q: Status of pthreads support?

Samuel Tardieu (tardieu@autan.enst.fr)
11 Aug 1994 15:49:20 GMT

Guido.van.Rossum@cwi.nl writes:

> What's the status of the pthreads stuff? I was hoping it might make
> it into 1.0.3.

I didn't put any new features in 1.0.3 -- but the work has been done!
You can ftp it from ftp://ftp.cwi.nl/pub/python/threads.tar.gz. Just
untar this into the python root directory. You need to do:

./configure --with-thread
make clean
(edit Modules/Setup to enable the thread module)
make

I reworked the thread.c file (splitting it in different files per
system) and Tim Peters wrote a pthreads version which worked with
KSR's pthreads implementation (based on pthreads draft 5). I don't
think I could get this to work with the Florida State University
pthreads implementation for SunOS 4.x.x (based on draft 6) but maybe I
remember it wrong, and maybe it's just my lack of understanding of the
pthreads compile time options :-) Anyway there are also working
versions of Python threads (not based on pthreads) for Solaris 2.x
threads and for IRIX 4 / IRIX 5 threads.

Is the thread module supposed to work with SunOS light-weight processes ?
I installed the threads library into my python source tree, modified
my configure.in to enable light-weight-processes library when run
with --with-thread option:

*** configure.in.old Thu Aug 11 17:16:13 1994
--- configure.in Thu Aug 11 17:16:13 1994
***************
*** 94,99 ****
--- 94,102 ----
LIBOBJS="$LIBOBJS thread.o"])
AC_HAVE_LIBRARY(thread, [AC_DEFINE(WITH_THREAD)
LIBS="$LIBS -lthread"
+ LIBOBJS="$LIBOBJS thread.o"])
+ AC_HAVE_LIBRARY(lwp, [AC_DEFINE(WITH_THREAD)
+ LIBS="$LIBS -llwp"
LIBOBJS="$LIBOBJS thread.o"])
])

Then I ran autoconf, to produce a new configure script, and
did configure python by: ./configure --with-thread

I tried this piece of code with the new executable:

---cut here---
import thread
import time

def f(*args):
for i in [1, 2, 3]:
time.sleep(1)
print i

thread.start_new_thread(f, (1,))
thread.start_new_thread(f, (1,))
thread.start_new_thread(f, (1,))
print "Exiting"
---cut here

The output is listed below:

Exiting
1
2
3
1
2
3
1
2
3

Threads are executed in order and only when the main program finishes.

I'm sure I missed something, but what ?

Sam

--
"La cervelle des petits enfants, ca doit avoir comme un petit gout de noisette"
                                                       Charles Baudelaire