g_type_register_static and thread-safety



Hello,

Almost all get_type() functions contain code
like

GType
whatever_get_type (void)
{
  static GType object_type = 0;

  if (!object_type)
    {
      static const GTypeInfo object_info =
      { ...  };

      object_type = g_type_register_static (G_TYPE_OBJECT, "Whatever", &object_info, 0);
    }

  return object_type;
}

Is this thread-safe?  I cannot see any guards in
g_type_register_static that prevent a second type-node from
being allocated in the obvious race condition...

Am i missing something?
The gtype docuemtnation does not mention thread-safety of this function.

thanks,
dave



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