//----------------------------------------------------- // le.cc: condiciĆ³n de carrera //----------------------------------------------------- #include #include #include #include #include //----------------------------------------------------- using namespace std::literals; //----------------------------------------------------- const size_t N = 1; //----------------------------------------------------- std::latch latch(2 * N); //----------------------------------------------------- void seccion_critica(char c) { for (char i = 0; i < 10; ++i) std::cout << c; std::cout << '\n'; } //----------------------------------------------------- void lector(char c) { latch.arrive_and_wait(); while (true) { seccion_critica(c); } } //----------------------------------------------------- void escritor(char c) { latch.arrive_and_wait(); while (true) { seccion_critica(c); } } //----------------------------------------------------- int main() { for (size_t i = 0; i < N; ++i) { std::thread(lector, '0' + i).detach(); std::thread(escritor, 'a' + i).detach(); } std::this_thread::sleep_for(10ms); } //-----------------------------------------------------