(Since you mentioned threads, I'm going to assume that you have POSIX stream functions at your disposal.)
There is a function for this purpose pthread_once. Anywhere you need to be sure that it is initializealready called, write:
pthread_once(&init_once, initialize);
where is init_oncedetermined by the static duration of storage and, possibly, with external communication, if necessary, how pthread_once_t init_once.
source
share