1 // { dg-do run }
2 // { dg-additional-options "-pthread" { target pthread } }
3 // { dg-require-effective-target c++11 }
4 // { dg-require-gthreads "" }
5
6 #include <mutex>
7 #include <testsuite_hooks.h>
8
9 struct Lockable
10 {
11 static int tries;
12
lockLockable13 void lock() { }
unlockLockable14 void unlock() { }
try_lockLockable15 bool try_lock() { return ++tries != 2; }
16 };
17
18 int Lockable::tries = 0;
19
test01()20 void test01()
21 {
22 Lockable l1, l2, l3;
23 std::mutex m1, m2;
24
25 VERIFY( std::try_lock(l1, l2, l3) == 1 );
26 VERIFY( Lockable::tries == 2 );
27
28 Lockable::tries = 0;
29 VERIFY( std::try_lock(m1, l1, l2, l3) == 2 );
30 VERIFY( Lockable::tries == 2 );
31
32 Lockable::tries = 0;
33 VERIFY( std::try_lock(l1, l2, l3, m1) == 1 );
34 VERIFY( Lockable::tries == 2 );
35
36 Lockable::tries = 0;
37 VERIFY( std::try_lock(m1, l1, l2, l3, m2) == 2 );
38 VERIFY( Lockable::tries == 2 );
39 }
40
main()41 int main()
42 {
43 test01();
44 }
45