摘要:
此处有两个线程,一个作为生产者,把数据放入队列中,一个作为消费者,把数据从队列中取出,所以对两个线程而言,这个队列是共用的,所以要加锁进行保护。 #include "stdafx.h" #include <iostream> #include <thread> #include <mutex> #i 阅读全文
posted @ 2020-01-14 17:18
缘随风烬
阅读(668)
评论(0)
推荐(0)
摘要:
多线程互斥锁的使用条件是:有多个线程访问全局的临界资源(变量)。 #include <iostream> #include <thread> #include <mutex> using namespace std; std::mutex mt; int a[5] = { 1,2,3,4,5 }; 阅读全文
posted @ 2020-01-14 09:59
缘随风烬
阅读(606)
评论(0)
推荐(0)
浙公网安备 33010602011771号