I want to wait on both a file descriptor and a mutex, what's the recommended way to do this?

后端 未结 8 1262
-上瘾入骨i
-上瘾入骨i 2020-12-31 03:36

I would like to spawn off threads to perform certain tasks, and use a thread-safe queue to communicate with them. I would also like to be doing IO to a variety of file descr

8条回答
  •  轮回少年
    2020-12-31 04:08

    It seems nobody has mentioned this option yet:

    Don't run select/poll/etc. in your "main thread". Start a dedicated secondary thread which does the I/O and pushes notifications into your thread-safe queue (the same queue which your other threads use to communicate with the main thread) when I/O operations complete.

    Then your main thread just needs to wait on the notification queue.

提交回复
热议问题