Re: using of fork() in multithreaded application

Taylor R Campbell <[email protected]>
Newsgroups gmane.os.netbsd.devel.kernel
Message-ID <[email protected]>
> Date: Fri, 24 Jan 2025 16:45:29 +0300
> From: Valery Ushakov <[email protected]>
> 
> That reminds me... (sorry if hijacking the thread).
> 
> When a user-supplied malloc is used (dmalloc &c, or program's own
> malloc like e.g. in inferno-os), they do not override jemalloc fork
> hooks as that's not part of malloc "API contract" so to say.  jemalloc
> hooks are run on fork with unitialized jemalloc internals.
> 
> What is the right corse of action here?

The right course of action is to define the symbols:

_malloc_prefork
_malloc_postfork
_malloc_postfork_child

These zero-argument functions are invoked at the obvious times in
libc's fork() function.  There's an example in src/lib/libbsdmalloc.

(This is obviously NetBSD-specific, but so is any API contract around
overriding the symbols malloc/free and expecting them to be usable
after fork at all.)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.