//test.cpp
#include <stdio.h>
#include <iostream>
#include <thread>
#include <mutex>
std::mutex mMutex;
using namespace std;
static int count=0;
static int MAX=5000;
static int line=0;
static int line_count=5;
void thread1(){
while(1){
if(count <MAX ){
mMutex.lock();
if(count <MAX ){
std::cout<<"A: "<<++count<<" ";
if(++line == line_count){
std::cout<<endl;
line = 0;
}
}else{
break;
}
mMutex.unlock();
}
}
}
void thread2(){
while(1){
if(count <MAX ){
mMutex.lock();
if(count <MAX ){
std::cout<<"B: "<<++count<<" ";
if(+
c++11 thread --多线程编译报错问题解决办法
最新推荐文章于 2023-09-21 22:57:33 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)