If mutex::try_lock() is called in a thread that already owns the mutex,
the behavior is undefined. The patch fixes the issue by creating another
thread, where the call is allowed.
Differential Revision: https://reviews.llvm.org/D94656
#include <cstdlib>
#include <cassert>
+#include "make_test_thread.h"
#include "test_macros.h"
std::mutex m;
+void do_try_lock() {
+ assert(m.try_lock() == false);
+}
+
int main(int, char**) {
{
m.lock();
std::lock_guard<std::mutex> lg(m, std::adopt_lock);
- assert(m.try_lock() == false);
+ std::thread t = support::make_test_thread(do_try_lock);
+ t.join();
}
m.lock();
#include <cstdlib>
#include <cassert>
+#include "make_test_thread.h"
#include "test_macros.h"
std::mutex m;
+void do_try_lock() {
+ assert(m.try_lock() == false);
+}
+
int main(int, char**) {
{
std::lock_guard<std::mutex> lg(m);
- assert(m.try_lock() == false);
+ std::thread t = support::make_test_thread(do_try_lock);
+ t.join();
}
m.lock();