Re: Are g_try_malloc() and g_free() thread-safe?



I was given and found some answers to my questions.  thought I'd share
for the good of the curious.

On Mon, Feb 07, 2005 at 03:41:42PM -0800, Ben Johnson wrote:
...
> how do you remove the risk?  you have to compile libc with _REENTRANT?

g_malloc(), g_free(), and associated functions are wrappers for the libc
malloc() and free().  I'm told that when the program is linked against a
thread library (not sure which thread lib... maybe all of them?) there's
some symbol magic that happens and thread safe versions of these
functions in the thread library are called instead.  (I'm paraphrasing,
so this may not be entirely accurate... or may be in need of serious
correction, but that's my understanding.)

> Also, the g_mem_set_vtable() function does not appear to be thread safe.

if g_mem_set_vtable() is used, it MUST be called BEFORE any other glib
function, so this is a non-issue.

BTW, I also found out that g_malloc() (and therefore all glib functions
that use g_malloc()) will call abort() if the wrapped malloc() fails.
Does everyone know that?  I was surprised to find out.  I think this
tidbit could use a little more publicity than the blurb in the glib docs
about g_try_malloc().

- Ben




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