This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Fwd: local equivalent for pthread_once() in glibc?
- From: Chris Aoki <christopher dot aoki at oracle dot com>
- To: libc-alpha at sourceware dot org
- Cc: Chris Aoki <christopher dot aoki at oracle dot com>
- Date: Tue, 25 Apr 2017 14:19:37 -0700
- Subject: Fwd: local equivalent for pthread_once() in glibc?
- Authentication-results: sourceware.org; auth=none
- References: <9EBFE06E-AF1D-48E9-85AB-B74C048438B1@oracle.com>
One of my colleagues suggested that I forward the question
below to the libc-alpha alias which would increase my chances
of reaching a glibc malloc expert. Actually my main question
(in the original message, below) is a general one, since situations
calling for pthread_once() can presumably occur in other contexts.
Chris Aoki
p.s. The secondary question, which is specific to glibc malloc, is
whether ptmalloc_init() can be called concurrently by multiple threads.
> Begin forwarded message:
>
> From: Chris Aoki <christopher.aoki@oracle.com>
> Subject: local equivalent for pthread_once() in glibc?
> Date: April 25, 2017 at 10:50:41 AM PDT
> To: libc-help@sourceware.org
> Cc: Chris Aoki <christopher.aoki@oracle.com>
>
> I have a question about glibc internals.
>
> Is there a private glibc function equivalent to pthread_once()?
>
> I have a structure that is frequently accessed after initialization
> so putting a lock around initialization and a check for initialization
> would add considerable overhead. Normally one would use pthread_once()
> in this situation, but my colleagues tell me that adding a reference to an
> external function is prohibited within libc.so. I see a macro __libc_once()
> but it does not appear to synchronize:
>
> /* Define once control variable. */
> #define __libc_once_define(CLASS, NAME) CLASS int NAME = 0
>
> /* Call handler iff the first call. */
> #define __libc_once(ONCE_CONTROL, INIT_FUNCTION) \
> do { \
> if ((ONCE_CONTROL) == 0) { \
> INIT_FUNCTION (); \
> (ONCE_CONTROL) = 1; \
> } \
> } while (0)
>
> Any clues appreciated. Thanks
>
> Chris Aoki