unique_lock加锁
作者:互联网
#include <iostream>
#include <mutex>
#include <thread>
std::mutex mutex;
void msg_func()
{
std::unique_lock<std::mutex> unique(mutex);
while(1)
{
std::cout << "do something" << std::endl;
std::chrono::milliseconds second(1000);
std::this_thread::sleep_for(second);
}
}
int main()
{
std::thread mythread(&msg_func);
getchar();
return 0;
}
$ g++ unique_lock.cpp -std=c++11 -pthread
$ ./a.out
do something
do something
标签:std,do,加锁,lock,include,mutex,unique 来源: https://www.cnblogs.com/zhangxuechao/p/16558843.html