Sequential lock synchronization primitive example
#include <atomic>
#include <iostream>
#include <thread>
#include <vector>
struct Data
{
int a;
int b;
int c;
};
int main(int argc, char** argv)
{
std::cout << "Press Enter to stop..." << std::endl;
std::vector<std::thread> threads;
for (int thread = 0; thread < 4; ++thread)
{
threads.emplace_back([&lock, thread]()
{
for (;;)
{
Data data = lock.Read();
if ((data.a == 100) && (data.b == 200) && (data.c == 300))
{
std::cout << "Thread " << thread << " stopped!" << std::endl;
return;
}
}
});
}
std::cin.get();
lock = Data{ 100, 200, 300 };
for (auto& thread : threads)
thread.join();
return 0;
}
Sequential lock synchronization primitive.
Sequential lock synchronization primitive definition.