David Blume's GitList
Repositories
testcode.git
Code
Commits
Branches
Tags
Search
Tree:
9444cb1
Branches
Tags
c++11
main
start
testcode.git
product
thread_with_lambda.cpp
Experimenting with lamda and threads.
David Blume
commited
9444cb1
at 2016-01-10 18:20:39
thread_with_lambda.cpp
Blame
History
Raw
#include <thread> #include <mutex> #include <iostream> #include "thread_with_lambda.hpp" namespace { std::mutex my_mutex; std::thread worker; } void thread_with_lambda() { uint32_t ticks = 10; std::lock_guard<std::mutex> lock(my_mutex); if (worker.joinable()) worker.join(); worker = std::thread([=]{ for(uint32_t tick = 0; tick <= ticks; tick++) { std::cout << "count " << tick << std::endl; } }); }