OSF DCE Application Development Guide--Core Components
Programming with Threads
process, but the lock owner will not exist to unlock it. Therefore, the resource protected
by the lock will be permanently unavailable.
The fact that there may be mutexes outstanding only becomes a problem if your code
attempts to lock a mutex that could be locked by another thread at the time of the fork().
This means that you cannot call outside of your own code between the call to fork( ) and
the call to exec(). Note that a call to malloc(), for example, is a call outside of the
currently executing application program and may have a mutex outstanding. The
following code obeys these guidelines and is therefore safe:
fork ();
a = 1+2; /* some inline processing */
exec();
Similarly, if your code calls some of your own code that does not make any calls outside
of your code and does not lock any mutexes that could possibly be locked in another
thread, then your code is safe.
One solution to the problem of calling fork( ) in a multithreaded environment exists.
(Note that this method will not work for server application code or any other application
code that is invoked by a callback from a library.) Before an application performs a
fork( ) followed by something other than exec(), it must cancel all of the other threads.
After it joins the canceled threads, it can safely fork( ) because it is the only thread in
existence. This means that libraries that create threads must establish cancel handlers
that propagate the cancel to the created threads and join them. The application should
save enough state so that the threads can be recreated and restarted after the fork( )
processing completes.
8.2 Using Signals
The following subsections cover three topics: types of signals, DCE Threads signal
handling, and alternatives to using signals.
8.2.1 Types of Signals
Signals are delivered as a result of some event. UNIX signals are grouped into the
following four categories of pairs that are orthogonal to each other:
• Terminating and synchronous
• Terminating and asynchronous
• Nonterminating and synchronous
• Nonterminating and asynchronous
The action that DCE Threads takes when a particular signal is delivered depends on the
characteristics of that signal.
124245 Tandem Computers Incorporated 8−5