drd/tests/swapcontext: Improve the portability of this test further
[valgrind.git] / drd / tests / std_mutex.cpp
blob7c3333eb15d8cdb5ad7092e1a937310dd5aa8ac4
1 // See also https://bugs.kde.org/show_bug.cgi?id=416286
3 #include <mutex>
4 #include <iostream>
5 #include <thread>
6 #include <vector>
8 class counter {
9 public:
10 counter(): mutex() {}
11 void get() { std::unique_lock<std::mutex> lock(mutex); }
13 private:
14 std::mutex mutex;
17 static counter& get_counter()
19 static counter manager;
20 return manager;
23 static void do_work()
25 get_counter().get();
28 int main()
30 std::vector<std::thread> v;
32 for (int i = 0; i < 16; i++)
33 v.emplace_back([]{ do_work(); });
35 for (auto& t : v)
36 t.join();
38 std::cerr << "Done.\n";