// Sistemas Operacionais
// Cássio Pinheiro
// Sincronizando Tarefas com Flag
#include <iostream>
#include <thread>
using namespace std;
bool saida = false;
void thr1( void ) {
cout << "Iniciando 1" << endl;
while( ! saida );
cout << "Fim 1" << endl;
}
void thr2( void ) {
cout << "Iniciando 2" << endl;
cout << "Fim 2" << endl;
this_thread::sleep_for( chrono::milliseconds( 2000 ));
saida = true;
}
int main() {
cout << "Main ID " << this_thread::get_id() << endl;
thread t1( thr1 );
thread t2( thr2 );
t1.join();
t2.join();
return( 0 );
}
To embed this program on your website, copy the following code and paste it into your website's HTML: