[gnutls-devel] [TLS] multiple clients in one process (was: Re: Deployment ... Re: This working group has failed)

Nico Williams nico at cryptonector.com
Sun Dec 1 20:07:31 CET 2013

On Sun, Dec 1, 2013 at 3:40 AM, Nikos Mavrogiannopoulos <nmav at gnutls.org> wrote:
> The more I think about static initialization of mutexes the more I think
> they are not a good idea for a library. How would you deinitialize a
> statically initialized mutex? Never? Then you get a memory/resource leak
> in the PAM case you are referring to. As these modules are opened with
> dlopen() and dlclosed later they leave the static mutex initialized.

This is what atexit() and thread-specific destructors are for.  Also,
global locks don't really need destruction, and most apps that use
them never destroy them.  And on last dlclose() then re-dlopen() the
RTLD should setup a brand new bss and re-map data, so there's no real
problem with leaving locks initialized.

On BSD/Unix/Linux systems there's no real problem with leaking
init-time resources anyways.  And even on Windows, I suspect a library
like GnuTLS never gets unloaded.

> If you deinitialize on the last call to the deinitialization function
> then assuming you have other threads calling the global initialization
> function in parallel you may even get crashes during that
> deinitialization if they try to lock it.

See above.


More information about the Gnutls-devel mailing list