Thread specific data for GLib




While testing out the thread-safety patches to GLib,
I ran into one problem that I don't see how to
solve without adding thread-specific data to our
set of primitives -

In g_logv, there is a static variable g_log_depth which
is used to detect recursion in a error message handler
and abort in that case.

This can't be solved by putting a lock around g_log(),
because it wouldn't be a good idea to hold that lock
when calling out to the error handler. (Especially
since some random set of other locks may be held
before g_message() or g_error() is called, so there
is a huge chance for deadlock)

Supporting thread private data, would require adding
something like:

 guint (*new_private_index) (GDestroyNotify destructor);
 void (*set_private) (guint index, gpointer data);
 gpointer (*get_private) (guint index);

[ stolen from NSPR, pretty much ]

to the threadfuncs. It would then be easy to provide,
on top of that, a more "G-ish" interface that provided
the optional ability to associate data with character
keys instead of numeric ID's. (I.e., something along
the lines of GDataSet / GDataList)

Regards,
                                        Owen



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