摘要: lock_guard(自动加锁, 自动解锁, 读取失败就一直等待) lock_guard<mutex> lgd(g_mutex); unique_lock(自动加锁, 自动解锁, 根据块语句锁定) unique_lock<mutex> ulk(g_mutex); 完整代码 #include<thre 阅读全文
posted @ 2021-07-03 14:25 python我的最爱 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 将一个线程移动到另外一个线程,其中的一个线程被销毁 // // Created by Administrator on 2021/7/3. // #include<thread> #include<iostream> #include<cstdlib> using namespace std; // 阅读全文
posted @ 2021-07-03 14:20 python我的最爱 阅读(207) 评论(0) 推荐(0) 编辑
摘要: 使用swap进行两个线程的交换 #include<thread> #include<iostream> using namespace std; //交换线程 int main1() { thread t1([](){cout << "fangfang"<<endl;}); thread t2([] 阅读全文
posted @ 2021-07-03 14:03 python我的最爱 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 第一步: 设置unique_lock<mutex> ulk(m) //设定锁定 第二步: 每一个线程在循环中等待, cv.wait(ulk) //不是该出现的场合等着 第三步: cv.notify_all() //通知其他的线程,进行执行 // // Created by Administrator 阅读全文
posted @ 2021-07-03 13:47 python我的最爱 阅读(401) 评论(0) 推荐(0) 编辑