[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Are malloc_hooks impossible to use in multi-threaded program?

From: Tom Horsley
Subject: Are malloc_hooks impossible to use in multi-threaded program?
Date: Thu, 26 May 2005 14:10:55 -0400

I've been trying to use the malloc_hooks documented in glibc to gather
some information, and I have reached the point that I need someone to
either tell me what I am doing wrong, or confirm that the current
implementation of the hooks is uttery unusable in a multi-threaded
program. Consider this:

I setup my hooks.

I start a bunch of threads.

On thread enters a malloc routine and I get control in my hook.

In order to eventually pass the call on to the real malloc function,
I have to set the hooks back to their original value, then call the
proper malloc function.

While the hook is set to the original value, another thread calls
a malloc function - now my hook has been completely bypassed because
it is not currently set.

Am I missing something obvious about how to use these hooks? Or is
is really impossible to be sure you always get control of every
malloc call in every thread?

It seems to me like the whole interface is wacko. Instead of having
to change global hook variables back and forth, it would make more
sense to forward calls to the old hook values you saved, and for glibc
to implement malloc so the hooks are statically initialized to
point to the "real" malloc routines, so there are never any NULL
hook pointers and you never have to modify global data during the
operation of multiple threads.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]