DBus threading question

Schmottlach, Glenn glenn.schmottlach at harman.com
Thu Dec 11 04:18:49 PST 2008


If I recall correctly, the bindings that I mention (GLib and C++) do in fact use poll() to check for activity on the incoming descriptor. Still, are there any issues with both threads "polling" (via select or poll) on the same socket descriptor. I guess I have to assume the poll/select implementation will do the appropriate locking to guarantee only a single thread polls at any one time. Is this correct or am I missing something?

Also, is it safe to call methods on the server from a signal handler which is invoked from the thread calling the mainloop (e.g. the "main" thread in my example)? In general, is it better to make method calls in one thread and receive signals in another? Is that the accepted pattern?



-----Original Message-----
From:	dbus-bounces at lists.freedesktop.org on behalf of Thiago Macieira
Sent:	Thu 12/11/2008 2:51 AM
To:	dbus at lists.freedesktop.org
Cc:	
Subject:	Re: DBus threading question

Schmottlach, Glenn wrote:
>How do both threads block on the same transport without interfering with
> one another (e.g. who gets the first chance to check for messages and
> handle it)?

They don't.

Only one can block the transport at a time.

It's recommended that the thread that is listening for external events 
(incoming signals and calls) not block the transport, but instead use 
select(2) or poll(2) to be notified of activity.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358





More information about the dbus mailing list