1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // UNSUPPORTED: libcpp-has-no-threads 11 12 // <atomic> 13 14 // struct atomic_flag 15 16 // void clear(memory_order = memory_order_seq_cst); 17 // void clear(memory_order = memory_order_seq_cst) volatile; 18 19 #include <atomic> 20 #include <cassert> 21 main()22int main() 23 { 24 { 25 std::atomic_flag f; // uninitialized 26 f.clear(); 27 assert(f.test_and_set() == 0); 28 f.clear(); 29 assert(f.test_and_set() == 0); 30 } 31 { 32 std::atomic_flag f; 33 f.clear(std::memory_order_relaxed); 34 assert(f.test_and_set() == 0); 35 f.clear(std::memory_order_relaxed); 36 assert(f.test_and_set() == 0); 37 } 38 { 39 std::atomic_flag f; 40 f.clear(std::memory_order_release); 41 assert(f.test_and_set() == 0); 42 f.clear(std::memory_order_release); 43 assert(f.test_and_set() == 0); 44 } 45 { 46 std::atomic_flag f; 47 f.clear(std::memory_order_seq_cst); 48 assert(f.test_and_set() == 0); 49 f.clear(std::memory_order_seq_cst); 50 assert(f.test_and_set() == 0); 51 } 52 { 53 volatile std::atomic_flag f; 54 f.clear(); 55 assert(f.test_and_set() == 0); 56 f.clear(); 57 assert(f.test_and_set() == 0); 58 } 59 { 60 volatile std::atomic_flag f; 61 f.clear(std::memory_order_relaxed); 62 assert(f.test_and_set() == 0); 63 f.clear(std::memory_order_relaxed); 64 assert(f.test_and_set() == 0); 65 } 66 { 67 volatile std::atomic_flag f; 68 f.clear(std::memory_order_release); 69 assert(f.test_and_set() == 0); 70 f.clear(std::memory_order_release); 71 assert(f.test_and_set() == 0); 72 } 73 { 74 volatile std::atomic_flag f; 75 f.clear(std::memory_order_seq_cst); 76 assert(f.test_and_set() == 0); 77 f.clear(std::memory_order_seq_cst); 78 assert(f.test_and_set() == 0); 79 } 80 } 81