]> git.ipfire.org Git - thirdparty/libvirt.git/commit
Fix updating of haveTheBuck in RPC client to be race-free
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 7 Dec 2011 14:46:39 +0000 (14:46 +0000)
committerDaniel Veillard <veillard@redhat.com>
Thu, 8 Dec 2011 03:27:19 +0000 (11:27 +0800)
commite970863746448a299533a5b3b4b2cecba361544c
tree6ac39405a0b1564cc6e222c2f29b3be3ec0382c0
parent50a4f49c19e2953f8c4262a3fc6cd50d4e64229e
Fix updating of haveTheBuck in RPC client to be race-free

When one thread passes the buck to another thread, it uses
virCondSignal to wake up the target thread. The variable
'haveTheBuck' is not updated in a race-free manner when
this occurs. The current thread sets it to false, and the
woken up thread sets it to true. There is a window where
a 3rd thread can come in and grab the buck.

Even if this didn't lead to crashes & deadlocks, this would
still result in unfairness in the buckpassing algorithm.

A better solution is to *never* set haveTheBuck to false
when we're passing the buck. Only set it to false when there
is no further thread waiting for the buck.

* src/rpc/virnetclient.c: Only set haveTheBuck to false
  if no thread is waiting
src/rpc/virnetclient.c