NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/50094: not all threads woken up when multiple threads waiting with keven on same kqueue



The following reply was made to PR kern/50094; it has been noted by GNATS.

From: Christof Meerwald <cmeerw%cmeerw.org@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: kern/50094: not all threads woken up when multiple threads
 waiting with keven on same kqueue
Date: Mon, 27 Jul 2015 21:17:58 +0200

 I think I now know what is going on here.
 
 For events that have neither EV_ONESHOT and EV_CLEAR set, the knote is
 removed from the kqueue, the kqueue is unlocked, the event is
 re-checked, the kqueue is locked again and the knote is re-added to
 the kqueue.
 
 The problem here is that there is a good chance that some of the
 threads will see the kqueue being empty when woken up (while another
 thread has removed the knote from the kqueue and is re-checking the
 event) and go back to sleep.
 
 A potential straightforward fix appears to be to add a cv_broadcast
 call after the knote has been re-added to the kqueue.
 
 
 Index: kern_event.c
 ===================================================================
 RCS file: /cvsroot/src/sys/kern/kern_event.c,v
 retrieving revision 1.83
 diff -u -r1.83 kern_event.c
 --- kern_event.c        2 Mar 2015 19:24:53 -0000       1.83
 +++ kern_event.c        27 Jul 2015 19:05:30 -0000
 @@ -1266,6 +1266,7 @@
                                 kq->kq_count++;
                                 kn->kn_status |= KN_QUEUED;
                                 kq_check(kq);
 +                               cv_broadcast(&kq->kq_cv);
                         }
                         if (nkev == kevcnt) {
                                 /* do copyouts in kevcnt chunks */
 
 
 Christof
 
 -- 
 
 http://cmeerw.org                              sip:cmeerw at cmeerw.org
 mailto:cmeerw at cmeerw.org                   xmpp:cmeerw at cmeerw.org
 


Home | Main Index | Thread Index | Old Index