c++ - epoll_wait() in a thread after close() -
i have main thread , worker thread. worker thread's code looks this:
thread = ::std::thread([this]() { struct epoll_event events[50]; (;;) { if (int const n = epoll_wait(efd, events, 50, -1)) { //...
i hoping close(efd)
in main thread cause worker thread's epoll_wait()
call return, doesn't happen. can exit worker thread's infinite loop?
your best bet use explicit signal (by mean, signal in ordinary sense; not posix signal) main thread epoll worker thread.
the technique of using pipe purpose tried , true, there better options: check out eventfd. use it, create eventfd file descriptor , add epoll set. signal main thread writing 8-byte value (a value of 1 fine).
when worker thread sees event on eventfd, knows has been signalled , should act accordingly.
the main advantage on using pipe requires single file descriptor, , don't have worry possibility of blocking when write pipe.
Comments
Post a Comment