hello.cpp (1001B)
1 #include <atomic> 2 #include <iostream> 3 #include <numeric> 4 #include <stdexcept> 5 #include <thread> 6 #include <vector> 7 8 struct thread_state { 9 std::atomic<int> &destroyed; 10 11 ~thread_state() 12 { 13 destroyed.fetch_add(1); 14 } 15 }; 16 17 int 18 main() 19 { 20 std::vector<int> values(128, 2); 21 std::atomic<int> total{0}; 22 std::atomic<int> destroyed{0}; 23 std::atomic<unsigned __int128> wide{0}; 24 std::thread worker([&]() { 25 thread_local thread_state state{destroyed}; 26 27 try { 28 throw std::runtime_error("worker"); 29 } catch (const std::runtime_error &) { 30 total.store(std::accumulate(values.begin(), values.end(), 0)); 31 } 32 }); 33 34 worker.join(); 35 if (destroyed.load() != 1) 36 return 1; 37 wide.store((unsigned __int128)1 << 100); 38 if (wide.load() != (unsigned __int128)1 << 100) 39 return 1; 40 try { 41 if (total.load() != 256) 42 return 1; 43 throw std::runtime_error("musllvm C++ OK"); 44 } catch (const std::runtime_error &error) { 45 std::cout << error.what() << '\n'; 46 } 47 std::cout.flush(); 48 return std::cout.good() ? 0 : 1; 49 }