Re: Are g_try_malloc() and g_free() thread-safe?
- From: Ben Johnson <ben blarg net>
- To: gtk-list gnome org
- Subject: Re: Are g_try_malloc() and g_free() thread-safe?
- Date: Mon, 7 Feb 2005 21:29:59 -0800
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
] [Thread Prev