No need for separate threads waiting for accept(2) and stdin - use poll/select here. Instead of conditional variable, create a pipe between threads (you already have threads if we talk about CVs), wait on it in the same poll and write to it when the event happens.