Manpages - dispatch_once.3

The

function provides a simple and efficient mechanism to run an initializer exactly once, similar to

Well designed code hides the use of lazy initialization. For example:

FILE *getlogfile(void) { static dispatch_once_t pred; static FILE *logfile;

dispatch_once(&pred, ^{ logfile = fopen(MY_LOG_FILE, “a”); });

return logfile; }

The

function is a wrapper around

Author: dt

Created: 2022-02-20 Sun 15:03