From owner-freebsd-current Tue Jul 2 16:20:16 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id F391037B400 for ; Tue, 2 Jul 2002 16:20:10 -0700 (PDT) Received: from rwcrmhc51.attbi.com (rwcrmhc51.attbi.com [204.127.198.38]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9F32743E0A for ; Tue, 2 Jul 2002 16:20:10 -0700 (PDT) (envelope-from julian@elischer.org) Received: from InterJet.elischer.org ([12.232.206.8]) by rwcrmhc51.attbi.com (InterMail vM.4.01.03.27 201-229-121-127-20010626) with ESMTP id <20020702232010.MDPP24728.rwcrmhc51.attbi.com@InterJet.elischer.org>; Tue, 2 Jul 2002 23:20:10 +0000 Received: from localhost (localhost.elischer.org [127.0.0.1]) by InterJet.elischer.org (8.9.1a/8.9.1) with ESMTP id QAA99131; Tue, 2 Jul 2002 16:07:38 -0700 (PDT) Date: Tue, 2 Jul 2002 16:07:36 -0700 (PDT) From: Julian Elischer To: Terry Lambert Cc: Garrett Wollman , Jonathan Lemon , current@FreeBSD.ORG Subject: Re: additional queue macro In-Reply-To: <3D222CA4.80865822@mindspring.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Tue, 2 Jul 2002, Terry Lambert wrote: > Garrett Wollman wrote: > > < said: > > > Essentially, this provides a traversal of the tailq that is safe > > > from element removal, while being simple to drop in to those sections > > > of the code that need updating, as evidenced in the patch below. > > > > The queue macros always guaranteed that traversal was safe in the > > presence of deletions. Julian's change is erroneous and should be > > reverted for compatibility with the other implementations of queue(3). I would by the way argue that the statement "The queue macros always guaranteed that traversal was safe in the presence of deletions" to be false. Nowhere was this guaranteed, in fact the Manual page goes to lengths to NOT do this.. note: /* TailQ Deletion. */ while (!TAILQ_EMPTY(&head)) { n1 = TAILQ_FIRST(&head); TAILQ_REMOVE(&head, n1, entries); free(n1); } /* Faster TailQ Deletion. */ n1 = TAILQ_FIRST(&head); while (n1 != NULL) { n2 = TAILQ_NEXT(n1, entries); free(n1); n1 = n2; } TAILQ_INIT(&head); The above taken from the man page examples. The one that killed me (why I wrote the debug code) was: /* * Move any threads that should be suspended from the run queue * to the suspend queue. */ TAILQ_FOREACH(from run queue) { if (something) { TAILQ_REMOVE(element from run queue) TAILQ_INSERT_TAIL(onto suspend queue) } } Now, at first glance, the documentation suggests this should work, even though we know it won't. but it doesn't crash.. it just terminates on the first transfer because it reaches the end of the queue.. the suspend queue that is.. > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message