diff options
author | erikchen <erikchen@chromium.org> | 2015-09-08 10:50:22 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-08 17:51:18 +0000 |
commit | 9c98c005f4ea59dd9425a4ee5d4e278f1c00ad8c (patch) | |
tree | 4b31ab5d26b7eb0df922b63cac91aac666529792 /base/synchronization | |
parent | b6da1f7c02e9fdf92bc07bb8a139a376c1179456 (diff) | |
download | chromium_src-9c98c005f4ea59dd9425a4ee5d4e278f1c00ad8c.zip chromium_src-9c98c005f4ea59dd9425a4ee5d4e278f1c00ad8c.tar.gz chromium_src-9c98c005f4ea59dd9425a4ee5d4e278f1c00ad8c.tar.bz2 |
mac: Add a hack to condition_variable_posix.cc to avoid a crash.
The Darwin pthreads subsystem has a bug that can cause the program to crash if a
conditional variable is destroyed after it has been signalled, but before it has
been waited on. This hack is a solution proposed by Apple in its own developer
forums.
BUG=517681
Review URL: https://codereview.chromium.org/1323293005
Cr-Commit-Position: refs/heads/master@{#347736}
Diffstat (limited to 'base/synchronization')
-rw-r--r-- | base/synchronization/condition_variable_posix.cc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/base/synchronization/condition_variable_posix.cc b/base/synchronization/condition_variable_posix.cc index 013284c..c9a2ec4 100644 --- a/base/synchronization/condition_variable_posix.cc +++ b/base/synchronization/condition_variable_posix.cc @@ -42,6 +42,20 @@ ConditionVariable::ConditionVariable(Lock* user_lock) } ConditionVariable::~ConditionVariable() { +#if defined(OS_MACOSX) + // This hack is necessary to avoid a fatal pthreads subsystem bug in the + // Darwin kernel. http://crbug.com/517681. + { + base::Lock lock; + base::AutoLock l(lock); + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 1; + pthread_cond_timedwait_relative_np(&condition_, lock.lock_.native_handle(), + &ts); + } +#endif + int rv = pthread_cond_destroy(&condition_); DCHECK_EQ(0, rv); } |