From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Richard Todd Newsgroups: gmane.lisp.guile.devel Subject: Re: scm_i_fraction_reduce thread safety Date: Sun, 11 Jan 2004 23:22:29 -0600 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <40022F15.30903@vzavenue.net> References: <3FD85844.3060108@ccrma> <1071170342.1217.60.camel@flare> <87wu91mxhf.fsf@zip.com.au> <87k73z1la9.fsf@zagadka.ping.de> <87ad4ve61r.fsf@zip.com.au> <87hdz3xocn.fsf@zagadka.ping.de> <87zncuat0g.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1073885092 21024 80.91.224.253 (12 Jan 2004 05:24:52 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 12 Jan 2004 05:24:52 +0000 (UTC) Cc: Bill Schottstaedt , guile-devel@gnu.org, Carl Witty , Marius Vollmer Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Jan 12 06:24:39 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AfuZ5-0003ik-00 for ; Mon, 12 Jan 2004 06:24:39 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AfvWO-0006zk-9j for guile-devel@m.gmane.org; Mon, 12 Jan 2004 01:25:56 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AfvVv-0006fM-1l for guile-devel@gnu.org; Mon, 12 Jan 2004 01:25:27 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AfvV3-0004yn-FZ for guile-devel@gnu.org; Mon, 12 Jan 2004 01:25:06 -0500 Original-Received: from [66.171.59.140] (helo=smtp.vzavenue.net) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AfvV1-0004uM-Qn for guile-devel@gnu.org; Mon, 12 Jan 2004 01:24:31 -0500 Original-Received: from vzavenue.net (125.155.171.66.subscriber.vzavenue.net [66.171.155.125]) by smtp.vzavenue.net (Mirapoint Messaging Server MOS 3.2.4-GA) with ESMTP id BCN87308; Mon, 12 Jan 2004 00:22:30 -0500 (EST) User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en Original-To: Kevin Ryde In-Reply-To: <87zncuat0g.fsf@zip.com.au> X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.2 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 Xref: main.gmane.org gmane.lisp.guile.devel:3198 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3198 Kevin Ryde wrote: > Marius Vollmer writes: > >>User code should only use scm_numerator and scm_denominator to access >>parts of the fraction object and those functions will first reduce the >>fraction (in a thread safe way). Wouldn't that be enough? > > > Yep, though it seems a shame the accessors have to be slowed down just > so printing and equality can write back. I may not fully understand this, but after reading through the messages on the list, and having been awake for 36 hours, I can't help but think at least two things: 1) If you are worried about thread safety, the most fool-proof C interface probably does not allow separate access to numerator and denominator, since they need to be read in one atomic operation to ensure consistent results in the face of other mutating code. 2) Aren't (numerator frac) and (denominator frac) themselves other examples of would-be readers that might have to 'write back' in this setup? According to r5rs they return the reduced value. For the speed issue in general, doesn't it come down to whether the extra gcd()s of eager reduction would be cheaper than the mutex_lock()s of lazy reduction? If I'm thinking straight, the mutex only seems necessary if SCM_FRACTION_REDUCED(n) == #f, so as long as you don't mutate/reduce/mutate/reduce in a tight loop, there may not be much mutexing at all. Seems like it could be tried both ways. Richard _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel