David Blume's GitList
Repositories
testcode.git
Code
Commits
Branches
Tags
Search
Tree:
56e9725
Branches
Tags
c++11
main
start
testcode.git
product
thread_with_lambda.cpp
Add .clang-format
dblume
commited
56e9725
at 2023-08-12 23:24:26
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; } // namespace void thread_with_lambda() { uint32_t ticks = 10; std::lock_guard<std::mutex> lock(my_mutex); worker = std::thread([=] { for (uint32_t tick = 0; tick <= ticks; tick++) { std::cout << __PRETTY_FUNCTION__ << " count " << tick << std::endl; } }); if (worker.joinable()) worker.join(); }