程序中thread01和thread02分别是两个线程的入口函数,如下那些选项的输出是可能的? #include <iostream> #include <thread> #include <Windows.h> #include <mutex> using namespace std; mutex mu; mutex me; int totalNum = 1; int anotherNum = 0; void thread01() { while (totalNum > 0) { mu.lock(); cout << "Thread1, totalNum is "<<totalNum << endl; totalNum–; me.lock(); anotherNum++; cout <<"Thread1, anotherNum is "<<anotherNum<<endl; me.unlock(); Sleep(100); mu.unlock(); } } void thread02() { while (totalNum > 0) { me.lock(); anotherNum += 2; mu.lock(); totalNum–; mu.unlock(); Sleep(100); me.unlock(); } }
区块链毕设网qklbishe.com为您提供问题的解答 程序中thread01和thread02分别是两个线程的入口函数,如下那些选项的输出是可能的?
#include <iostream>
#include <thread>
#include <Windows.h>
#include <mutex>
using namespace std;
mutex mu;
mutex me;
int totalNum = 1;
int anotherNum = 0;
void thread01()
{
while (totalNum > 0)
{
mu.lock();
cout << "Thread1, totalNum is "<<totalNum << endl;
totalNum–;
me.lock();
anotherNum++;
cout <<"Thread1, anotherNum is "<<anotherNum<<endl;
me.unlock();
Sleep(100);
mu.unlock();
}
}
void thread02()
{
while (totalNum > 0)
{
me.lock();
anotherNum += 2;
mu.lock();
totalNum–;
mu.unlock();
Sleep(100);
me.unlock();
}
}
从业7年-专注一级市场
微信:btc9767
TELEGRAM :https://t.me/btcok9
具体资料介绍
web3的一级市场千万收益的逻辑
进群点我
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台-javagopython毕设 » 程序中thread01和thread02分别是两个线程的入口函数,如下那些选项的输出是可能的?
#include <iostream>
#include <thread>
#include <Windows.h>
#include <mutex>
using namespace std;
mutex mu; mutex me;
int totalNum = 1; int anotherNum = 0; void thread01()
{
while (totalNum > 0)
{
mu.lock();
cout << "Thread1, totalNum is "<<totalNum << endl;
totalNum–; me.lock(); anotherNum++;
cout <<"Thread1, anotherNum is "<<anotherNum<<endl; me.unlock(); Sleep(100); mu.unlock();
}
}
void thread02()
{
while (totalNum > 0)
{
me.lock(); anotherNum += 2; mu.lock(); totalNum–; mu.unlock(); Sleep(100);
me.unlock();
}
}
微信:btc9767
TELEGRAM :https://t.me/btcok9
具体资料介绍
web3的一级市场千万收益的逻辑
进群点我
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台-javagopython毕设 » 程序中thread01和thread02分别是两个线程的入口函数,如下那些选项的输出是可能的?
#include <iostream>
#include <thread>
#include <Windows.h>
#include <mutex>
using namespace std;
mutex mu; mutex me;
int totalNum = 1; int anotherNum = 0; void thread01()
{
while (totalNum > 0)
{
mu.lock();
cout << "Thread1, totalNum is "<<totalNum << endl;
totalNum–; me.lock(); anotherNum++;
cout <<"Thread1, anotherNum is "<<anotherNum<<endl; me.unlock(); Sleep(100); mu.unlock();
}
}
void thread02()
{
while (totalNum > 0)
{
me.lock(); anotherNum += 2; mu.lock(); totalNum–; mu.unlock(); Sleep(100);
me.unlock();
}
}
进群点我
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台-javagopython毕设 » 程序中thread01和thread02分别是两个线程的入口函数,如下那些选项的输出是可能的?
#include <iostream>
#include <thread>
#include <Windows.h>
#include <mutex>
using namespace std;
mutex mu; mutex me;
int totalNum = 1; int anotherNum = 0; void thread01()
{
while (totalNum > 0)
{
mu.lock();
cout << "Thread1, totalNum is "<<totalNum << endl;
totalNum–; me.lock(); anotherNum++;
cout <<"Thread1, anotherNum is "<<anotherNum<<endl; me.unlock(); Sleep(100); mu.unlock();
}
}
void thread02()
{
while (totalNum > 0)
{
me.lock(); anotherNum += 2; mu.lock(); totalNum–; mu.unlock(); Sleep(100);
me.unlock();
}
}
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台-javagopython毕设 » 程序中thread01和thread02分别是两个线程的入口函数,如下那些选项的输出是可能的? #include <iostream> #include <thread> #include <Windows.h> #include <mutex> using namespace std; mutex mu; mutex me; int totalNum = 1; int anotherNum = 0; void thread01() { while (totalNum > 0) { mu.lock(); cout << "Thread1, totalNum is "<<totalNum << endl; totalNum–; me.lock(); anotherNum++; cout <<"Thread1, anotherNum is "<<anotherNum<<endl; me.unlock(); Sleep(100); mu.unlock(); } } void thread02() { while (totalNum > 0) { me.lock(); anotherNum += 2; mu.lock(); totalNum–; mu.unlock(); Sleep(100); me.unlock(); } }