[PATCH] Re: Threading problems in (Win)DBus

Olivier Hochreutiner olivier.hochreutiner at gmail.com
Tue Jul 10 03:37:31 PDT 2007


Hi,

After some more tries, it appears that the problem was a threading
problem, but not what we expected:

In the DBusConnection structure, io_path_acquired and
have_connection_lock being in the same bit field, they are stored in
memory in the same 32-bit word. Since only 32 bits can be written at a
time in memory, and not one single bit, when one is written, the other
is written too. And since they are protected by two different mutexes,
they are not protected one against the other.
For a better explanation of this, see http://en.wikipedia.org/wiki/Bit_field
In my previous post I reported that inserting a char[] in
DBusConnection between the two problematic variables made the issue
disappear. It is logical since the two bits are not in the same word
in memory anymore, then.

I attached a patch which just remove the use of bit field and replace
the bit variables by normal unsigned int. I see two drawbacks with it:

1) For each instance of DBusConnection, 28 bytes more of memory is needed
2) struct DBusConnection changed so it may lead to problems when it is
build as a shared object (binary incompatibility). Correct me if I am
wrong...

Oh and the fact that most of you could not reproduce the bug is
probably due to the fact that you did not have hyperthreaded CPUs. So
the bug still could occur, but much more seldom.

Best,

Olivier


More information about the dbus mailing list