Date: Sat, 24 Oct 1998 08:10:00 -0700 (PDT) From: Daniel Eischen <eischen@vigrid.com> To: freebsd-bugs@FreeBSD.ORG Subject: Re: kern/8375: pthread_cond_wait() spins the CPU Message-ID: <199810241510.IAA04757@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/8375; it has been noted by GNATS. From: Daniel Eischen <eischen@vigrid.com> To: dima@tejblum.dnttm.rssi.ru, eischen@vigrid.com Cc: freebsd-gnats-submit@FreeBSD.ORG, jb@FreeBSD.ORG Subject: Re: kern/8375: pthread_cond_wait() spins the CPU Date: Sat, 24 Oct 1998 11:08:34 -0400 (EDT) > IMO, your _thread_kern_sched_[un]lock() is a bad idea. Theses functions > defeat the idea of spinlocks. What is the need to do _SPINLOCK/_SPINUNLOCK > when scheduling is blocked? Your code do it a lot. OTOH, spinlocks are > designed exactly to make rescheduling harmless. And they works; the only > problem is that spinlocks are released in a bit wrong time. (BTW, why you > disable scheduling in pthread_cond_signal and pthread_cond_broadcast?) Especially for pthread_cond_broadcast, you do not want to get preempted while walking the condition variable queue to signal waiters. If you are preempted, other threads run, time increments, and that can cause a thread that would normally be signalled to be woken up with a timeout (assuming it was doing a pthread_cond_timedwait). At the time of the pthread_cond_broadcast, all threads that are currently on the waiting list should be woken up. You do not want the scheduler to run and wakeup some of these threads. Another thing that looks possible, is that the condition variable queue can be corrupted. When a thread is on the queue and it times out, I don't see where the scheduler removes it from the queue (_thread_queue_remove isn't used). What if it timesout and immediately does another pthread_cond_timedwait? I'll look at this some more later today - perhaps I'm just overlooking something. Dan Eischen eischen@vigrid.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199810241510.IAA04757>