This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
How to use the malloc hooks in a thread-safe manner
- From: "Fabian van der Werf" <fabian dot van dot der dot werf at altenpts dot nl>
- To: libc-help at sourceware dot org
- Date: Tue, 16 Nov 2010 10:29:48 +0100
- Subject: How to use the malloc hooks in a thread-safe manner
- Reply-to: fabian dot van dot der dot werf at altenpts dot nl
Hi All,
The code example of the malloc hooks (http://www.gnu.org/s/libc/manual/html_node/Hooks-for-Malloc.html) removes the hooks and reinstalls them a bit later to prevent infinite recursion when performing.
How do I adapt this code to work in a multithreaded application? Temporarily removing the hooks will cause calls to malloc (and free, etc) from other threads to completely bypass the hooks. Any synchronization primitives in the hook functions will not work, because when the hooks are unhooked the other threads don't pass through the synchronization.
Regards,
Fabian