#include "pch.h"
#include <iostream>
#include <thread>
#include <mutex>
#include <list>
using namespace std;
#if 0
int ticketCount = 100;
std::mutex mtx;
void sellTicket(int index)
{
while (ticketCount > 0)
{
{
lock_guard<std::mutex> lock(mtx);
if (ticketCount > 0)
{
cout << "窗口:" << index << "卖出第:" << ticketCount << "张票!" << endl;
ticketCount--;
}
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
int main()
{
list<std::thread> tlist;
for (int i = 1; i <= 3; ++i)
{
tlist.push_back(std::thread(sellTicket, i));
}
for (std::thread &t : tlist)
{
t.join();
}
cout << "所有窗口卖票结束!" << endl;
return 0;
}
#endif