]>
Commit | Line | Data |
---|---|---|
62d19588 | 1 | // { dg-options "-std=gnu++2a" } |
83a1beee | 2 | // { dg-do run { target c++2a } } |
62d19588 | 3 | // { dg-additional-options "-pthread" { target pthread } } |
83a1beee TR |
4 | // { dg-require-gthreads "" } |
5 | ||
99dee823 | 6 | // Copyright (C) 2020-2021 Free Software Foundation, Inc. |
83a1beee TR |
7 | // |
8 | // This file is part of the GNU ISO C++ Library. This library is free | |
9 | // software; you can redistribute it and/or modify it under the | |
10 | // terms of the GNU General Public License as published by the | |
11 | // Free Software Foundation; either version 3, or (at your option) | |
12 | // any later version. | |
13 | ||
14 | // This library is distributed in the hope that it will be useful, | |
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | // GNU General Public License for more details. | |
18 | ||
19 | // You should have received a copy of the GNU General Public License along | |
20 | // with this library; see the file COPYING3. If not see | |
21 | // <http://www.gnu.org/licenses/>. | |
22 | ||
23 | #include <atomic> | |
24 | #include <thread> | |
25 | #include <mutex> | |
26 | #include <condition_variable> | |
27 | #include <type_traits> | |
28 | #include <chrono> | |
29 | ||
30 | #include <testsuite_hooks.h> | |
31 | ||
32 | int | |
33 | main () | |
34 | { | |
35 | using namespace std::literals::chrono_literals; | |
36 | ||
37 | std::mutex m; | |
38 | std::condition_variable cv; | |
10522ed1 | 39 | std::unique_lock<std::mutex> l(m); |
83a1beee TR |
40 | |
41 | long aa; | |
42 | long bb; | |
43 | ||
44 | std::atomic<long*> a(nullptr); | |
45 | std::thread t([&] | |
46 | { | |
10522ed1 JW |
47 | { |
48 | // This ensures we block until cv.wait(l) starts. | |
49 | std::lock_guard<std::mutex> ll(m); | |
50 | } | |
83a1beee TR |
51 | cv.notify_one(); |
52 | a.wait(nullptr); | |
53 | if (a.load() == &aa) | |
54 | a.store(&bb); | |
55 | }); | |
83a1beee TR |
56 | cv.wait(l); |
57 | std::this_thread::sleep_for(100ms); | |
58 | a.store(&aa); | |
59 | a.notify_one(); | |
60 | t.join(); | |
61 | VERIFY( a.load() == &bb); | |
62 | return 0; | |
63 | } |