Subject: pthread, pth select
To: None <netbsd-users@netbsd.org>
From: Jorgen Lundman <lundman@lundman.net>
List: netbsd-users
Date: 10/03/2003 14:25:18
Porting something that uses allegro to NetBSD, (not -current since that is a
different story). pkgsrc/wip has allegro but I've been looking at it myself.
I've come across the situation now that it spawns two helper threads, both uses
a call to select() to do sleeping. (No fd_sets passed to it).
I find when I link against -lpthread//usr/pkg/lib/libpthread.so.14 (from pth, at
least, the /usr/pkg/include/pthread.h is the pth "pthread" compatible mode) that
the select() calls do not release the CPU.
If I stick in a pthread_yield_np(); before or after the select() everything
works. (allegro, and the game ported) however, this clearly isn't ideal.
Seemed to be hints around as to that the problem is that the kernel can only
have one select() call, and that pth should in theory, collect all together and
do the one call for me, but this must not be working.
Is that perhaps because I am linking against the pthread.h, as opposed to,
pth.h? There is a lot of source changes to do for it to work against pth.h directly.
Now it seems a shame that it uses select() purely to sleep. But looking at the
functions that pthread.h is aware, only sleep() can be used to pause, and it
only takes "seconds" which is far too little granularity.
Similarly I could use pthread to wait on signal, but sigalarm only takes
seconds. (actually hmm, does setitimer take a timeval - this could be my best
solution).
Anything else to look into?
Lundy
--
Jorgen Lundman | <lundman@lundman.net>
Unix Administrator | +81 (0)3 -5456-2687 ext 1017 (work)
Shibuya-ku, Tokyo | +81 (0)90-5578-8500 (cell)
Japan | +81 (0)3 -3375-1767 (home)