//---------------------------------------------------- // secuencial.cc //---------------------------------------------------- #include #include #include //---------------------------------------------------- using namespace std::literals; //---------------------------------------------------- std::atomic start = false, stop = false; //---------------------------------------------------- void seccion_critica() { std::cout << "[" << std::this_thread::get_id() << "]: "; for (size_t i = 0; i < 10; ++i) std::cout << i; std::cout << std::endl; } //---------------------------------------------------- void hebra() { while (!start) std::this_thread::yield(); while (!stop) seccion_critica(); } //---------------------------------------------------- int main() { std::thread threads[1]; for (auto &t : threads) t = std::thread(hebra); start = true; std::this_thread::sleep_for(1ms); stop = true; for (auto &t : threads) t.join(); } //----------------------------------------------------