dbus_g_thread_init()

John (J5) Palmieri johnp at redhat.com
Wed Sep 13 09:49:46 PDT 2006


On Wed, 2006-09-13 at 18:36 +0200, Julien PUYDT wrote:
> Havoc Pennington a écrit :
> >> The idea is to have a public dbus_g_init(gboolean is_threaded) function.
> >> Most libraries have an init function so this is fine and we need it
> >> anyway since the type system is currently initialized by dbus_g_bus_get
> >> and there are instances where you need to use dbus types before you get
> >> a connection.
> > 
> > I think this is kind of a downgrade; init functions are in general evil 
> > (I consider g_type_init() a design bug)
> > 
> > The thread init function exists for only two reasons:
> >  - possible performance concerns
> >  - dbus not having built-in thread primitives, so someone had to
> >    provide the glib or qt ones
> > 
> > But it's deliberately an init function only for threading; there's 
> > deliberately no generic dbus_init.
> 
> There are other problems with init functions :
> - what if they're called several times ?

It returns doing nothing.  In the threaded case if threads are not yet
inited it initializes the threads and returns.  We do this already.

> - what if they're called late ?

The purpose of an init function is to be called before you call any
other part of the library.  It is fine to call them late as long as you
haven't used the API yet.

> More specifically, if an application loads plugins, and those plugins 
> use DBus :
> - what happens if several of them initialize dbus ;

Same thing that happens now with thread initing.  We check a static
variable to make sure we don't run the code twice.

> - what happens if my application already has several threads when those 
> plugins kick in ?

Same thing that happens now with threads and plugins.

> There's also the case of using a library which uses dbus behind your 
> back (doesn't avahi do that ?).

gnome-vfs does that too.  It works.

> Ekiga will soon have parts of it coming in as plugins, so these 
> threading questions really matter to me.

If you are using the file chooser you are already using plugin D-Bus
threading in a gnome environments.  0.92 fixed any issues with late
thread initialization.

-- 
John (J5) Palmieri <johnp at redhat.com>



More information about the dbus mailing list