Mysterious SIGALRM's using pthreads & sockets

I'm trying to port a C++ application to Solaris 8/Sparc using the new

Forte 6 development tools/libraries and a new Sun E250 Server.

I'm using various pthreads components (threads/mutexes/conditions/signal

handling), as well as your standard socket programming calls (socket/bind/

accept/etc.). I've managed to get all the code compiling fine without

too much trouble (save the insane list of options required for what I'd

consider pretty standard code). All the code seems to be working now

with the exception of a multithreaded program.

The program starts out with two threads working as a simplified web

server and as an asynchronous signal handler, and then upon a form

submission starts up a couple more threads: a producer and consumer,

and a separate thread performing a task at a fixed time interval.

When my program starts up, the two threads perform wonderfully. But

once I start up the others, the program runs for a about 3-5 seconds

and then receives an alarm signal (SIGALRM). The signal causes

everything to shutdown and exit (and I've even tried blocking it in

every way imaginable -- at the thread and process levels).

I've searched high and low and found no information on what might be

causing this. I tried a bunch of different compiler options, from:

(compile) CC -mt -instances=static -g -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT

(link) CC -mt -lpthread -lposix4 -lsocket -lnsl -library=%none,Cstd,Crun,iostream

to all kinds of combinations of the POSIX flags (additionally, _POSIX_PER_PROCESS_TIMERS and _POSIX_C_SOURCE), and the Solaris native

threading flags (-lthread, -lrt, -D_REENTRANT, etc.). The _POSIX_C_SOURCE

define I found mentioned in documentation somewhere, but unfortunately

Forte's header files are broken so as to break everything when you

actually try to use it.

I've also tried using forte's graphical debugger -- stepping through

instruction-by-instruction, and it doesn't appear to have any

correlation to the code; it's happening at random locations. I've

even tried cutting out the code for the signal handling and for the fixed-interval timer to narrow it down, but no luck. I'm starting

to think there must be a bug in Solaris' pthreads implementation.

I guess my next step is to break down and replace my pthreads code

with Solaris native code, but I'm hoping there's a saviour out there

for me...Pleeeaseee save me from having to do that ;)

Thanks,

Mike

[2641 byte] By [mikedickey] at [2007-11-25 23:42:02]
# 1
Reverse the order of the posix4 and pthread library in your link command:(link) CC -mt -lposix4 -lpthread -lsocket -lnsl -library=%none,Cstd,Crun,iostream-Raj
rajn at 2007-7-5 18:49:32 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2
Also make sure that you have applied the latest recommended Solaris 8 patches from Sun. I had very similar problems, mostly related to semaphores and synchronization, before I applied the patches.Good luck!
attermann at 2007-7-5 18:49:32 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3
Things like sleep(), setitimer(), usleep() or alarm() will cause this. You cannot use these in your multithreaded programs, use nanosleep() or poll(0, 0, milli_timeout) instead.
lprimak at 2007-7-5 18:49:32 > top of Java-index,Development Tools,Solaris and Linux Development Tools...