Re: mutex doubt
- From: Emmanuele Bassi <ebassi gmail com>
- To: Tristan Van Berkom <tvb gnome org>
- Cc: "gtk-app-devel-list gnome org" <gtk-app-devel-list gnome org>
- Subject: Re: mutex doubt
- Date: Tue, 6 Dec 2011 19:24:30 +0000
hi;
On 6 December 2011 18:14, Tristan Van Berkom <tvb gnome org> wrote:
Or, can glib programs which don't make use of GObject use
threads at all ?
sure.
Must _those_ programs still call g_thread_init()
before using threads ?
before GLib 2.31, yes; after, no.
It seems that the pthread library itself requires at least that pthread_init()
be called once before using threads, is it called implicitly by every
function that might require threads ? (like g_mutex_init() ?)
threading support is always initialized, in GLib 2.31.
Speaking of which, I just stumbled on some really odd documentation
for g_mutex_init(), it says there:
 "It is not necessary to initialize a mutex that has been created
that has been statically allocated."
Anyone care to mention what that means ? Mustn't a mutex at least be
zero initialized if
declared on the stack ? i.e. GMutex my_mutex = { 0, }; ?
if it's in static storage, i.e. it has been declared as:
static GMutex my_mutex;
then no, you don't need to initialize it, as the C spec defines that
the static storage has to be zero-initialized.
if it's been placed inside a struct or union, then yes: you need to
explicitly initialize it using g_mutex_init().
ciao,
Emmanuele.
--
W: http://www.emmanuelebassi.name
B: http://blogs.gnome.org/ebassi/
- Follow-Ups:
- RES: mutex doubt
- From: Marcelo Elias Del Valle - SYSMAP SOLUTIONS - Claro MA-SP -
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]