This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fwd: local equivalent for pthread_once() in glibc?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]