tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: using of fork() in multithreaded application
> Date: Fri, 24 Jan 2025 16:45:29 +0300
> From: Valery Ushakov <uwe%stderr.spb.ru@localhost>
>
> 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.)
Home |
Main Index |
Thread Index |
Old Index