Bug 44609 - fix bug in logic of windows condition variables
Summary: fix bug in logic of windows condition variables
Status: RESOLVED FIXED
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: unspecified
Hardware: Other Windows (All)
: lowest minor
Assignee: Havoc Pennington
QA Contact: John (J5) Palmieri
URL:
Whiteboard:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2012-01-09 18:43 UTC by Marcus Brinkmann
Modified: 2012-02-21 07:22 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments
fix logic bug in windows condition variable (1019 bytes, patch)
2012-01-09 18:43 UTC, Marcus Brinkmann
Details | Splinter Review
Removed unused condvar_wake_all related code (6.16 KB, patch)
2012-02-20 04:26 UTC, Ralf Habacker
Details | Splinter Review

Description Marcus Brinkmann 2012-01-09 18:43:02 UTC
Created attachment 55362 [details] [review]
fix logic bug in windows condition variable

A year ago, I submitted a patch to fix a live lock in the windows condition variables implementation.  This patch had an obvious logic bug: in the wake all function, the live lock buster was wrapped in an if-clause which condition is always false.

The attached patch fixes this.
Comment 1 Simon McVittie 2012-01-23 05:58:20 UTC
Ralf, could you review this please? The patch looks sane to me but I don't speak fluent Windows.
Comment 2 Ralf Habacker 2012-01-23 08:39:37 UTC
Comment on attachment 55362 [details] [review]
fix logic bug in windows condition variable

Review of attachment 55362 [details] [review]:
-----------------------------------------------------------------

Hmmh, no test case and no receipt to be able to reproduce the problem, which this patch tries to fix. In fact adding this patch enables code, which has been never called before. Because this affects thread logic, which is always complicate, the impact of the code in the if(any) block need to be reviewed too. 


 
-  if (cond->list != NULL)
+  if (any)
Comment 3 Marcus Brinkmann 2012-01-23 08:59:00 UTC
Come on, don't be shy.  The condvar_wake_all function isn't even used anywhere in dbus, but only exists to match the POSIX interface for completeness.  Only condvar_wake_one is used.  And that's alright: Broadcasting a condition variable is a rare use case.

So, if you feel more comfortable with that, just rip out the condvar_wake_all implementation entirely.

As for the actual fix and code (just in case there is a lingering interest in having a cond_wake_all implementation in dbus), this is a good resource if you want to learn about the issues involved: http://www.cs.wustl.edu/~schmidt/win32-cv-1.html

Thanks,
Marcus
Comment 4 Simon McVittie 2012-02-15 03:32:51 UTC
(In reply to comment #3)
> The condvar_wake_all function isn't even used anywhere in dbus, but
> only exists to match the POSIX interface for completeness.

Well spotted. If this is the case, then its fairness (or lack of) isn't important (downgrading severity accordingly), and I'm inclined to delete the whole thing if we ever break API to drop support for third-party threading implementations (Bug #43744).
Comment 5 Ralf Habacker 2012-02-20 04:26:29 UTC
Created attachment 57310 [details] [review]
Removed unused condvar_wake_all related code
Comment 6 Simon McVittie 2012-02-20 04:46:04 UTC
Comment on attachment 57310 [details] [review]
Removed unused condvar_wake_all related code

Review of attachment 57310 [details] [review]:
-----------------------------------------------------------------

Sorry, we can't do this for API stability reasons.

One thing we *can* do is to remove support for threading implementations
other than those in libdbus (pthreads and Windows), essentially
making dbus_threads_init() equivalent to dbus_threads_init_default();
having done that, we can easily remove support for wake_all (the one
in the struct would be present-but-ignored, but on that branch
so is the rest of the struct). I thought my patches awaiting review on
Bug #43744 already did that, but that must have been in an earlier
version; I'll append a patch 7 that does.

Another possibility would be to remove the functions that *call*
condvar_wake_all, but not the struct member itself, make that
struct member optional (NULL allowed), and remove its Unix and
Windows implementations. I think it's actually better to do
what I proposed on Bug #43744, though.

::: dbus/dbus-threads.h
@@ -172,5 @@
>    DBusCondVarWaitFunction condvar_wait; /**< Function to wait on a condition */
>    DBusCondVarWaitTimeoutFunction condvar_wait_timeout; /**< Function to wait on a condition with a timeout */
>    DBusCondVarWakeOneFunction condvar_wake_one; /**< Function to wake one thread waiting on the condition */
> -  DBusCondVarWakeAllFunction condvar_wake_all; /**< Function to wake all threads waiting on the condition */
> - 

We can't make this change because it breaks ABI (rearranges the struct) - any third-party library supplying its own locking primitives would break.
Comment 7 Simon McVittie 2012-02-21 07:22:03 UTC
Fixed by deleting the offending code (but leaving the ABI unchanged), in Bug #43744. 1.5.10


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.