Date: Mon, 24 Jan 2022 11:30:41 -0800 From: Keith Packard <keithp@...thp.com> To: Sebastian Huber <sebastian.huber@...edded-brains.de>, Florian Weimer <fweimer@...hat.com> Cc: libc-coord@...ts.openwall.com Subject: Re: Constructors/destructors for thread-local objects? Sebastian Huber <sebastian.huber@...edded-brains.de> writes: > I have to admit that I didn't thought about dlopen(). You have to clear > .tbss and initialize .tdata for existing threads, so there must be some > way to get access to all existing threads. Wouldn't it be possible to > run the thread-local constructors in a signal handler? Probably not a good plan — most of the Posix API isn't usable from signal handlers (including malloc). *maybe* we could call this in the syscall return path of the target thread? Even then I worry about semantics of any mutexes or other consequences of running code from an unknown context. > Yes, the resource allocation issue with __cxa_thread_atexit() was one of > the reasons that let me think about the new sections. I would like to > support applications which do not dynamically allocate memory at all. Hrm. The more I think about this, the more I suspect the best we can do is initialize the memory to values defined in the DLL and let the library deal with more complex initialization once it gets invoked and is running in a known state. >> The destructors should probably take an iteration count as argument, and >> a return value that's non-zero if any action was taken by the >> destructor. I think this is needed because it is not always possible to >> destruct per-thread resources in a single pass. For example, a logger >> handle could be brought back to life if another destructor needs to log >> something. The C library would keep running all destructors until all >> of them signal that no work was left to do anymore. I can't imagine a context in which it would be safe to run these destructors though, unless you want to allow them to be run from another thread. -- -keith Download attachment "signature.asc" of type "application/pgp-signature" (833 bytes)
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.