Put attendant thread in background

This allow main thread to terminate without any error when each
car thread has terminated.
It's more accurate, because otherwise the attendant will wait
forever and block the program.
This commit is contained in:
Romain CLEMENT 2023-10-17 20:36:21 +02:00
parent 234c2bab0b
commit fad41c80b3

View File

@ -74,7 +74,10 @@ void attendant()
int main()
{
print("Car wash opening with " << N << " waiting spaces");
thread attendantThread(attendant);
attendantThread.detach();
vector<thread> cars {};
for(size_t i = 0; i < N+1; ++i)
{
@ -82,7 +85,6 @@ int main()
cars.push_back(std::move(t));
}
attendantThread.join();
for (auto &car: cars) {
car.join();
}