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

后端 未结 8 1216
-上瘾入骨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:09

    I've solved this exact problem using what you mention, pipe() and libevent (which wraps epoll). The worker thread writes a byte to its pipe FD when its output queue goes from empty to non-empty. That wakes up the main IO thread, which can then grab the worker thread's output. This works great is actually very simple to code.

提交回复
热议问题