Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to interrupt epoll_pwait with an appropriate signal?
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/2244466/interrupting-epoll-wait-with-a-non-io-event-no-signals">Interrupting epoll_wait with a non-IO event, no signals</a> </p> </blockquote> <p>I have a thread that is currently using epoll_wait to flag the arrival of data on some sockets. The timeout parameter is currently set to zero.</p> <p>However, the thread also does other tasks. What I want to do is change this so that if there is no work to be done then make it an indefinite or long time out. This will dramatically reduce wasted CPU cycles spinning when there is no actual work to do.</p> <p>The whole thing is driven mostly by the arrival of a message on a thread safe lock free queue.</p> <p>So, what I think should happen is I should wake up the thread from it's long timeout using epoll_pwait.</p> <p>However, I'm unsure what signal to send it and how this is done. I'm not familiar with Linux signals. </p> <p>The following is similar to what I currently have. Dramatically shorted to show the concept. If you spot a bug, don't bother pointing it out, this is just an illustration that I've typed in here to help you understand what I'm wanting to achieve.</p> <pre><code>// Called from another thread... void add_message_to_queue(struct message_t* msg) { add_msg(msg); raise( ? ); // wake the state machine? } // different thread to the above. main_thread() { struct message_t msg; while (msg = get_message_from_queue()) process_message(msg); timeout = work_available ? 0 : -1; nfds = epoll_pwait(epfd, events, MAX_EPOLL_EVENTS, timeout); for (i = 0; i &lt; nfds; ++i) { if ((events[i].events &amp; EPOLLIN) == EPOLLIN) { /// do stuff } } run_state_machines(); } </code></pre> <p>So I guess my question is really, is this the right way of going about it? and if so, what signal do I send and do I need to define a signal handler or can I use the signal disposition "ignore" and still be woken?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload