Debian Codegraph @

libstdc++-v3/testsuite/29_atomics/atomic_integral/wait_notify.cc

raw
1 // { dg-do run { target c++20 } }
2 // { dg-require-gthreads "" }
3 // { dg-add-options libatomic }
4 // { dg-additional-options "-pthread" { target pthread } }
5
6 // Copyright (C) 2020-2025 Free Software Foundation, Inc.
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
24 #include <atomic>
25 #include <thread>
26
27 #include <testsuite_hooks.h>
28
29 template<typename Tp>
30 void
31 check()
32 {
33 std::atomic<Tp> a{ Tp(1) };
34 VERIFY( a.load() == Tp(1) );
35 a.wait( Tp(0) );
36 std::thread t([&]
37 {
38 a.store(Tp(0));
39 a.notify_one();
40 });
41 a.wait(Tp(1));
42 t.join();
43 }
44
45 int
46 main ()
47 {
48 // check<bool> bb;
49 check<char>();
50 check<signed char>();
51 check<unsigned char>();
52 check<short>();
53 check<unsigned short>();
54 check<int>();
55 check<unsigned int>();
56 check<long>();
57 check<unsigned long>();
58 check<long long>();
59 check<unsigned long long>();
60
61 check<wchar_t>();
62 #if __cpp_char8_t
63 check<char8_t>();
64 #endif
65 check<char16_t>();
66 check<char32_t>();
67
68 check<int8_t>();
69 check<int16_t>();
70 check<int32_t>();
71 check<int64_t>();
72
73 check<uint8_t>();
74 check<uint16_t>();
75 check<uint32_t>();
76 check<uint64_t>();
77 return 0;
78 }