#include "iostream"
#include "thread"
#include "string"
#include "functional"
#include "mutex"
using namespace std;
std::mutex glock;
class Th{
public:
Th(){
}
void startThread(){
typedef std::function<void(int,std::string)> FN;
FN fn = [=](int id,std::string name){
volatile int count = 0;
while( (count++) < 5){
glock.lock();
std::cout << "fn: " << ", id=" << id << ", count=" << count << ", name=" << name << std::endl;
glock.unlock();
this_thread::sleep_for(chrono::milliseconds(1000)); //延时1秒
}
};
for (int id = 0; id < 3; id++){
std::string name = "n" + std::to_string(id);
std::thread t(fn,id,nam
c++11开多线程
最新推荐文章于 2019-01-31 00:34:27 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)