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

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -