LynxOS and POSIX - What the manual doesn't tell you

I'm collectiong here some hints, which I learnt during my POSIX programming activity with LynxOS (version 3), and which seemed to be unfindable elsewhere.
Be patient, I'm just writing up the text (Sep 2002).

signal & threads

Signal handlers are individual among threads. What you install in one thread is not effective in another, unless it's a child thread and the handler has been installed before the pthread_create() call. Already installed handlers remain active; child threads inherit handlers.

Contrarily to threads, new processes reset the signal handlers to SIG_DFL, whose meaning is explained in the signal(3) (LynxOS) or signal(7) (Linux) manual.

thread declaration and communication

Once you found out, how threads handle input and output parameters (Let's say, you are looking for equivalents of argc/argv[] and return/exit() from the plain unthreaded world), you either read and understood K&R completely and know its contents by heart or are wondering how to deal correctly the void* pointer. In principle, you can cast as cast can and just get along, but that would remove some of the implicite compiler checkings. The recommended way is to use casts where needed and leave the basic consistency checks to compiler and carefully designed header files like /usr/include/pthread.h.
#include <pthreads.h>

typedef int thr_comm;

static void* thread(void* dummy)
{
	thr_comm *status = (thr_comm*) dummy;
	*status = 3;
	pthread_exit(status);
}

caller()
{
pthread_attr_t thrAttr;
pthread_t thrPid;
thr_comm thrParam;

	/* ... */

	thrParam = 2;
	pthread_create(&thrPid, thrAttr, thread, &thrParam);

	/* ... */

}
The code sample above takes into account these considerations. The typedef is not necessary, but indicates that any more complicated parameter set, including struct can be used instead.

NB: Take care that the caller survives the end of the thread, or make the parameters static, because they are transferred (forth and back) by reference!

The alternative (and otherwise equivalent) way of returning parameters by return instead of pthread_exit() is deprecated. The pthread_exit() performs for example cleanup functions, which may have been defined by pthread_cleanup_push calls.

mutex

References

LynxOS, CES, ...

©Dirk Hoffmann, CPPM, 2000-2002