This is the mail archive of the 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]

Re: [PATCH] Provide pthread_atfork in libc_nonshared.a and libc.a.

On Wed, Oct 02, 2013 at 05:31:13PM -0400, Carlos O'Donell wrote:
> +/* The standard design pattern for making it optional to link against
> +   libpthread is to mark the function weak, test if the function
> +   address is non-zero and call the function, otherwise use a fallback.
> +   The problem with pthread_atfork is that there is no viable
> +   fallback.  If you need to do something during fork it has to be done
> +   via pthread_atfork.  This makes having libpthread optional and using
> +   pthread_atfork impossible.  We make it possible by providing
> +   pthread_atfork in libc_nonshared.a.  The real work of pthread_atfork
> +   is done by __register_atfork which is already provided in
> +   libc_nonshared.a.  It's included in libc_nonshared.a because

__register_atfork is in or libc.a, not in libc_nonshared.a.

> +   __dso_handle has to be unique to each DSO such that unloading the DSO
> +   can unregister the atfork handlers.  We build pthread_atfork again
> +   under a different file name and include it into libc_nonshared.a and
> +   libc.a. We keep pthread_atfork in libpthread_nonshared.a and
> +   libpthread.a for compatibility and completeness.
> +
> +   Applications that can't rely on a new glibc should use the following
> +   code to optionally include libpthread and still register a function
> +   via pthread_atfork i.e. use __register_atfork directly:
> +
> +   extern void *__dso_handle __attribute__ ((__weak__, __visibility__ ("hidden")));
> +   extern int __register_atfork (void (*) (void), void (*) (void), void (*) (void), void *);
> +
> +   static int __app_atfork (void (*prepare) (void), void (*parent) (void), void (*child) (void))

__ prefix is implementation namespace, so if you think this comment
is worthwhile, make it app_atfork rather than __app_atfork to avoid
teaching people bad habits.


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