Waiting on multiple events C++

前端 未结 4 551
后悔当初
后悔当初 2021-02-10 05:37

Is there a recommended way to wait on multiple inputs. For example I would like my program to be able to receive input from 3 sources:

Listen on a thread condition e.g.

4条回答
  •  孤独总比滥情好
    2021-02-10 06:33

    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.

提交回复
热议问题