//--------------------------------------------------------- // pthread.cc //--------------------------------------------------------- #include #include #include #include #include //--------------------------------------------------------- using namespace std::literals; //--------------------------------------------------------- const size_t N = 2; //--------------------------------------------------------- pthread_barrier_t barrera; //--------------------------------------------------------- void hebra(size_t yo) { std::string antes = std::to_string(yo) + ": antes\n", despues = std::to_string(yo) + ": después\n"; while (true) { std::cout << antes; pthread_barrier_wait(&barrera); std::cout << despues; } } //--------------------------------------------------------- int main() { pthread_barrier_init(&barrera, NULL, N); for (size_t i = 0; i < N; ++i) std::thread(hebra, i).detach(); std::this_thread::sleep_for(10ms); } //---------------------------------------------------------