You may have one or more routines that must be executed before any thread executes code in your facility, but that must be executed only once, regardless of the sequence in which threads start executing. For example, you may want to initialize mutexes, condition variables, or thread-specific data keys-each of which must be created only once-in an initialization routine. Multiple threads can call the pthread_once routine and DECthreads will ensure that the specified routine is called only once.
You can use the pthread_once routine to ensure that your initialization routine is executed only a single time, that is, by the first thread that tries to initialize the facility.
Alternately, you can statically initialize a mutex and a flag, and then simply lock the mutex and test the flag. In many cases, this is easier.
Finally, you may select initialization mechanisms, such as OpenVMS LIB$INITIALIZE, UNIX dynamic loader __init_ code, or Win32 DLL initialization handlers.