On 04/30, Oleg Nesterov wrote: > > > > pidfd_poll() can race with the exiting task, miss exit_code != 0, and return > > > zero. However, do_poll() won't block after that and pidfd_poll() will be called > > > again. > > > > Here also I didn't follow what you mean. If exit_code is read as 0 in > > pidfd_poll(), then in do_poll() the count will be 0 and it will block in > > poll_schedule_timeout(). Right? > > No. Please note the pwq->triggered check and please read __pollwake(). > > But if you want to understand this you can forget about poll/select. It is > a bit complicated, in particular because it has to do set_current_state() > right before schedule() and thus it plays games with pwq->triggered. But in > essence this doesn't differ too much from the plain wait_event-like code > (although you can also look at wait_woken/woken_wake_function). > > If remove_wait_queue() could happem before wake_up_all() (like in your pseudo- > code above), then pidfd_poll() or any other ->poll() method could miss _both_ > the condition and wakeup. But sys_poll() doesn't do this, so it is fine to miss > the condition and rely on wake_up_all() which ensures we won't block and the > next iteration must see condition == T. Oh, just in case... If it is not clear, of course I am talking about the case when wake_up_call() was already called when we check the condition. Otherwise everything is simple. Oleg.