[PATCH] [libcxx] Fix bug in shared_timed_mutex that could cause a program to hang.

Jeffrey Yasskin jyasskin at gmail.com
Thu Apr 2 12:54:31 PDT 2015


There must be better names for those variables than `gate1` and `gate2`.

It's weird that the condition_variable::wait_until() loops aren't using the predicate versions of wait_until() so they wouldn't need the loops. Even in C++98 mode where you'd have to name the predicates, it seems like it'd be worth it.

The fix itself looks correct to me.


================
Comment at: test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until_deadlock_bug.pass.cpp:28
@@ +27,3 @@
+const int total_readers = 2;
+std::atomic<int> readers_started = ATOMIC_VAR_INIT(0);
+std::atomic<int> readers_finished = ATOMIC_VAR_INIT(0);
----------------
Nit: Can't you initialize this as:

```
std::atomic<int> readers_started(0);
```

?

================
Comment at: test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until_deadlock_bug.pass.cpp:31
@@ +30,3 @@
+
+// Wait until the reader_one has a read lock then attempt to get the write lock.
+void writer_one() {
----------------
This comment is out of date.

================
Comment at: test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until_deadlock_bug.pass.cpp:45
@@ +44,3 @@
+  // Attempt to get the read lock. writer_one should be blocking us because
+  // writer_one is blocked by reader_one.
+  m.lock_shared();
----------------
"blocked by main()."

http://reviews.llvm.org/D8796

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list