From owner-freebsd-bugs Fri Oct 23 21:50:07 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id VAA14220 for freebsd-bugs-outgoing; Fri, 23 Oct 1998 21:50:07 -0700 (PDT) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id VAA14205 for ; Fri, 23 Oct 1998 21:50:05 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.8/8.8.5) id VAA11508; Fri, 23 Oct 1998 21:50:01 -0700 (PDT) Date: Fri, 23 Oct 1998 21:50:01 -0700 (PDT) Message-Id: <199810240450.VAA11508@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.ORG From: Daniel Eischen Subject: Re: kern/8375: pthread_cond_wait() spins the CPU Reply-To: Daniel Eischen Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR kern/8375; it has been noted by GNATS. From: Daniel Eischen 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 00:46:23 -0400 (EDT) BTW, pthread_mutex_lock also has the same problem as pthread_cond_wait if thread scheduling comes at an inopportune time: _SPINLOCK(&(*mutex)->lock); /* Process according to mutex type: */ switch ((*mutex)->m_type) { /* Fast mutexes do not check for any error conditions: */ case MUTEX_TYPE_FAST: /* * Enter a loop to wait for the mutex to be locked by the * current thread: */ while ((*mutex)->m_owner != _thread_run) { /* Check if the mutex is not locked: */ if ((*mutex)->m_owner == NULL) { /* Lock the mutex for this thread: */ (*mutex)->m_owner = _thread_run; } else { /* * Join the queue of threads waiting to lock * the mutex: */ _thread_queue_enq(&(*mutex)->m_queue, _thread_run); /* Unlock the mutex structure: */ _SPINUNLOCK(&(*mutex)->lock); /* Block signals: */ _thread_kern_sched_state(PS_MUTEX_WAIT, __FILE__, __LINE__); If thread scheduling is kicked off right after the last SPINUNLOCK, then you can also have a thread removed from the mutex queue, but it'll never get woken up. Dan Eischen eischen@vigrid.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message