mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-09 05:10:23 +00:00
drd/tests/std_mutex: Add a unit test for std::mutex
This commit is contained in:
39
drd/tests/std_mutex.cpp
Normal file
39
drd/tests/std_mutex.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// See also https://bugs.kde.org/show_bug.cgi?id=416286
|
||||
|
||||
#include <mutex>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
class counter {
|
||||
public:
|
||||
counter(): mutex() {}
|
||||
void get() { std::unique_lock<std::mutex> lock(mutex); }
|
||||
|
||||
private:
|
||||
std::mutex mutex;
|
||||
};
|
||||
|
||||
static counter& get_counter()
|
||||
{
|
||||
static counter manager;
|
||||
return manager;
|
||||
}
|
||||
|
||||
static void do_work()
|
||||
{
|
||||
get_counter().get();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::vector<std::thread> v;
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
v.emplace_back([]{ do_work(); });
|
||||
|
||||
for (auto& t : v)
|
||||
t.join();
|
||||
|
||||
std::cerr << "Done.\n";
|
||||
}
|
||||
Reference in New Issue
Block a user