The pth environment is a cooperative model. This means that there is only
one real thread in which all the others are emulated. If one of the
pth-threads no longer needs the cpu, for example because it is put to sleep
for some time, it has to return the control to the pth subsystem which will
continue execution with another waiting pth-thread.
However if you block your real thread by calling a blocking function like
sleep, select, read, etc. the entire program will be halted. This is
why each blocking function has an implementation within the pth library.
These functions are named after their original ones like pth_sleep,
pth_select, and so on.
The replacement functions will handle blocking calls in a special way to
make sure that the other pth-treads will continue to work.
So, if you want to use the pth library you should make sure, you don't block
your program, by always calling the replacement function if available. And
if you have code which will take a long time to execute, you should insert
calls to pth_yield. Otherwise this pth-thread will never return control to
the pth subsystem and this will block the other threads.
About your first testing program: You created a thread and then you start
writing os. Unfortunately you call sleep instead of pth_sleep. Your
main thread will block the entire program each time for one second and
because the pth subsystem is never executed, the other thread will never be
executed as well. The reason why you never saw any . may be because you
called pthread_join instead of pth_join. But this is only a wild guess,
because you posted the pthread version of your test program. However if you
call pth_join the execution of the main thread will be suspended and the pth
subsystem will execute the other thread. This thread is not cooperative as
well because you built the same busy loop which will never return
execution to the pth subsystem but this doesn't matter because your main
thread is already almost done.
The same applies to your second example. If you call select and accept
you can be sure your program blocks and the other threads will never be
executed.
Regards
Marc
On Fri, Oct 04, 2002 at 12:14:13PM +0200, Terry wrote:
ive found that out already, but what i was tryin to do was to show
that somethings wrong with pth's pthread lib.
i tried a few pthreaded programs and they all have problems with pth.
the prog i pasted here has only unparalleled output, but take this
one followed for example.
it wont even open a socket! and this time it doesnt look like
a serialization problem does it ?
what might be wrong with this one ?
also tested on openbsd and redhat linux.
thanks again in advance,
terry
msg00356/pgp0.pgp
Description: PGP signature