When multiple threads call IVEThreadCallOnce with a pointer to the same IVEThreadOnceFlag variable, it is guaranteed that the initialization function registered with IVEThreadCallOnce will be invoked once and that none of the threads will return until after the initialization function has been completed. This is useful for lazy initialization of something which may be used by multiple threads.
#include "ive_standards.h"
#include "ive_thread.h"
void IVEThreadCallOnce(void (*init_routine)(void), IVEThreadOnceFlag* p_once);
There is no Fortran interface.
The code fragment below guarantees that initialize_lut() is called only once no matter how many timers get_lut() is called.
#include "ive_standards.h"
#include "ive_thread.h"
static void initialize_lut(void);
static float* g_lut;
float*
get_lut(void)
{
static IVEThreadOnceFlag flag = IVE_ONCE_INIT;
IVEThreadCallOnce(initialize_lut, &flag);
return g_lut;
}
static
void
initialize_lut(void)
{
/*
* Initialize g_lut here.
*/
}
Inclusion of ive_standards.h sets certain feature-set macros. It is safest to include it before any other headers to avoid inconsistent definitions.
| categories | alphabetical |
modified May 7, 2002
Eric Branlund (eric@msg.ucsf.edu)