int main() {
thread t1([] {printer("*", 100); });
thread t2([] {printer("+", 100); });
t1.join();
t2.join();
}
void printer(string c, int num)
{
for (int i = 1; i <= num; i++)
{
cout << c;
}
cout << endl;
}
Right now this prints something like ****+++** I want it to print *** all in one line then +++ all in one line. We are not allowed to use mutex locks or block thread access to the printer function. The code must still be multithreaded.
Any ideas on how to do this?