4 ms·
But, say: for (;;) { /* ... */ if (pthread_once(&once_var, once_routine)) /* error */; /* ... */ } Here, we are ensuring that
by kazinator 12y ago
But, say:
for (;;) {
/* ... */
if (pthread_once(&once_var, once_routine))
/* error */;
/* ... */
}
Here, we are ensuring that once_routine is called exactly once.
ACCESS_ONCE to me strongly suggests that the value is accessed once and cached forever. E.g. ACCESS_ONCE(x) could expand to something like:
({
static __flag;
static typeof(x) __cached;
if (!__flag) {
__cached = (x);
__flag = 1;
}
__cached;
})
ANSI Common Lisp has load-time-value. You can use this anywhere:
(defun myfunc ()
(let ((foo (bar))
... ;; deeply nested
(let ((x (load-time-value (whatever))))
...))))
The load-time-value form is evaluated when the module is loaded and the value is stashed. Then whenever myfunc is called and that code is evaluated, the previously stashed value is retrieved; the (whatever) is not evaluated any more.