thread-safety of counters
adrian.s at samsung.com
Tue Feb 24 00:49:03 PST 2015
W dniu 23.02.2015 o 17:19, Simon McVittie pisze:
>> W dniu 23.02.2015 o 13:56, Simon McVittie pisze:
>>> This seems reasonable, but it would be good to know whether the
>>> counter is meant to be protected by a mutex. If so, why was that mutex
>>> not sufficient here? and if not, how do we avoid getting an incorrect
>>> value in the counter via concurrent access from different threads?
> ... but if they aren't protected by any mutex, then I don't see how
> these counters can ever have worked correctly in any threaded situation.
> If we have public APIs that use them (which we do), then we should
> probably make them atomic too (throwing away even more CPU caches in the
> process... but that's the price you pay for trying to be thread-safe).
Oh, now I understand, you talk about safety of actual values in a
counter object, not only about the reference count.
> Do you see what I mean about libdbus trying to be all things to all
> people, and only succeeding in doing them all badly? :-)
I am not there yet, but I think I am getting closer :-)
> Could you open a bug on bugs.freedesktop.org to track this, please?
> Ideally please attach your proposed patch,
Sure. Will do.
> and if you could do a new
> patch to make the counters themselves atomic, that would also be great.
If I dig into libdbus deep enough to understand it sufficiently, a patch
will probably 'emerge'.
More information about the dbus