From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Futures: Avoid creating the worker pool more than once Date: Fri, 09 Nov 2012 22:13:50 -0500 Message-ID: <87ehk2rvyp.fsf@tines.lan> References: <87a9uu9vpk.fsf@tines.lan> <87zk2rc3kz.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1352517260 21558 80.91.229.3 (10 Nov 2012 03:14:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 10 Nov 2012 03:14:20 +0000 (UTC) Cc: guile-devel@gnu.org To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Nov 10 04:14:30 2012 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TX1Wf-0007rR-Ft for guile-devel@m.gmane.org; Sat, 10 Nov 2012 04:14:29 +0100 Original-Received: from localhost ([::1]:50408 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TX1WW-0006QI-0Z for guile-devel@m.gmane.org; Fri, 09 Nov 2012 22:14:20 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:34653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TX1WS-0006Pv-Qa for guile-devel@gnu.org; Fri, 09 Nov 2012 22:14:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TX1WR-0006hJ-LL for guile-devel@gnu.org; Fri, 09 Nov 2012 22:14:16 -0500 Original-Received: from world.peace.net ([96.39.62.75]:60702) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TX1WR-0006hF-Gw; Fri, 09 Nov 2012 22:14:15 -0500 Original-Received: from turntable.mit.edu ([18.160.0.29] helo=tines.lan) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1TX1WK-0005HJ-GY; Fri, 09 Nov 2012 22:14:08 -0500 In-Reply-To: <87zk2rc3kz.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Thu, 08 Nov 2012 20:11:24 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 96.39.62.75 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:15133 Archived-At: ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Mark H Weaver skribis: > >> + ;; setting 'create-workers!' to a no-op is an optimization, but it is >> + ;; still possible for '%create-workers!' to be called more than once >> + ;; from different threads. Therefore, to avoid creating %workers more >> + ;; than once (and thus creating too many threads), we check to make >> + ;; sure %workers is empty within the critical section. > > Do you have a scenario where this happens? I'd hoped that the comment above was clear, but let me try again. If two threads simultaneously call 'make-future' before the worker pool has been created, then both threads can call 'create-workers!' (before it has been rebound), and from there both can enter '%create-workers!'. At that point, unless one of the threads is killed, it is guaranteed that both will enter the critical section: first one, and then the other (after the first one has unlocked the mutex). Thus, two worker pools will be created (though the first worker pool will become inaccessible). Mark