Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Issue 173059: Ensure that SyncWaiter condition variables cannot be destroyed during a broadcast (Closed)

Created:
11 years, 4 months ago by Mark Mentovai
Modified:
9 years, 7 months ago
Reviewers:
agl
CC:
chromium-reviews_googlegroups.com, John Grabowski, brettw
Visibility:
Public.

Description

Ensure that SyncWaiter (base/waitable_event_posix.cc) condition variables cannot be destroyed (pthread_cond_destroy) during a broadcast (pthread_cond_broadcast). SyncWaiter::Fire now holds the lock until the broadcast is complete. Given the lock ordering, this guarantees that the condition variable cannot be destroyed until it is safe to do so. Holding the lock through the broadcast is harmless, as pthread_cond_wait and pthread_cond_timedwait will simply block (if needed) until able to take the lock prior to returning. Ownership of the lock and condition variable is moved to SyncWaiter for better self-documentation. The only true functional change here, however, is the duration that SyncWaiter::Fire holds the lock. This bug caused hangs in optimized official release builds on the Mac when DCHECKS were optimized away. The DCHECK optimization was initially covered in bug 16512 r20497 and was backed out due to bug 16871 r20889. The optimization changed the timings just enough that we wound up hitting this case. On the Mac, pthread_cond_broadcast wound up blocking indefinitely (with a trashed stack) when its condition variable was destroyed beneath it; this caused other locks held by its thread to never be released, resulting in other threads becoming deadlocked and made the bug particularly difficult to diagnose. BUG=19710 TEST=Application works with no unexplained deadlocks, hanging, or crashing base_unittests (specifically WaitableEvent*) ipc_tests (especially IPCSyncChannelTest.ChattyServer, which would hang previously on the Mac with DCHECKs optimized away) Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=23790

Patch Set 1 #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+42 lines, -37 lines) Patch
M base/waitable_event_posix.cc View 8 chunks +42 lines, -37 lines 1 comment Download

Messages

Total messages: 3 (0 generated)
Mark Mentovai
This was really ludicrous to track down.
11 years, 4 months ago (2009-08-19 16:21:01 UTC) #1
agl
LGTM. Sorry about that. OSX appears to have different semantics for locking in this case ...
11 years, 4 months ago (2009-08-19 17:35:34 UTC) #2
Mark Mentovai
11 years, 4 months ago (2009-08-19 18:30:48 UTC) #3
agl@chromium.org wrote:
> LGTM. Sorry about that. OSX appears to have different semantics for
> locking in this case and something which was safe on Linux broke for you
> :(

No big deal, it was sort of fun to track the bug down.

> http://codereview.chromium.org/173059/diff/1/2
> File base/waitable_event_posix.cc (right):
>
> http://codereview.chromium.org/173059/diff/1/2#newcode87
> Line 87: lock_(),
> Isn't this line a no-op?

I like to keep it listed explicitly and in the order of construction, because
lock_ is used as the parameter to the ConditionVariable constructor on the next
line.

Mark

Powered by Google App Engine
This is Rietveld 408576698