From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.devel Subject: Re: Guile's I/O procedures should *not* do thread synchronization Date: Wed, 26 Mar 2014 20:45:09 +0100 Message-ID: <87vbv0oibe.fsf@pobox.com> References: <1395746068-20604-1-git-send-email-dfsr@riseup.net> <87lhvys6ug.fsf@pobox.com> <87vbv1ilzl.fsf_-_@yeeloong.lan> <878urxpds1.fsf@pobox.com> <87r45pht6w.fsf@yeeloong.lan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1395863125 20964 80.91.229.3 (26 Mar 2014 19:45:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 26 Mar 2014 19:45:25 +0000 (UTC) Cc: guile-devel@gnu.org To: Mark H Weaver Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Mar 26 20:45:36 2014 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 1WStlV-0005Z0-7i for guile-devel@m.gmane.org; Wed, 26 Mar 2014 20:45:33 +0100 Original-Received: from localhost ([::1]:49950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WStlU-000493-SW for guile-devel@m.gmane.org; Wed, 26 Mar 2014 15:45:32 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49955) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WStlL-000453-6W for guile-devel@gnu.org; Wed, 26 Mar 2014 15:45:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WStlF-00033Q-LU for guile-devel@gnu.org; Wed, 26 Mar 2014 15:45:22 -0400 Original-Received: from a-pb-sasl-quonix.pobox.com ([208.72.237.25]:49206 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WStlF-00033I-Gp for guile-devel@gnu.org; Wed, 26 Mar 2014 15:45:17 -0400 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id E3609F99E; Wed, 26 Mar 2014 15:45:16 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=qSc5CavI7F6eSwx3tMVXsXvui84=; b=OAtx2V MpQl2xnu5No5C/oMUsNoDWvuSS84TSjxzFc+KlJISJwl9kLbyYUP+jjyMWaw7N9E Cz5/a6JnqLsu92KbAalMwMN/wCsqFTVp2VV34r0BxnEiVHq+YWb+Kr76YNAwprVl CeTw70hdeWjItTL8aRK4eueVBIEx4CRqgoIxg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=ipCk3RYTJl2Ro4vtwn71dagVcZm8WCoP CG4JL3IOGv+gzzttxBLvhhfAUIgBvmwjdaqXL0FyOueaPO/M6zu9o8ZZDezyyuYP j2iLq1uOuFZqcRiZjgfq3nLsU89x6OGEL0ixVfk6H8ihskJJqEcZx6SNmg+SzfAB DqqbjYs3Yvg= Original-Received: from a-pb-sasl-quonix.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id DC0D7F99D; Wed, 26 Mar 2014 15:45:16 -0400 (EDT) Original-Received: from badger (unknown [88.160.190.192]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTPSA id E4A9BF99C; Wed, 26 Mar 2014 15:45:15 -0400 (EDT) In-Reply-To: <87r45pht6w.fsf@yeeloong.lan> (Mark H. Weaver's message of "Wed, 26 Mar 2014 11:32:07 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Pobox-Relay-ID: 27624AE0-B51F-11E3-A0FA-873F0E5B5709-02397024!a-pb-sasl-quonix.pobox.com X-detected-operating-system: by eggs.gnu.org: Solaris 10 X-Received-From: 208.72.237.25 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:17028 Archived-At: Hi, On Wed 26 Mar 2014 16:32, Mark H Weaver writes: > Andy Wingo writes: > >> It seems to work for glibc streams. Why do you think that thread >> synchronization is inappropriate for Guile if it works for glibc? > > In the Scheme world, things are very different. The Scheme standards > provide only one set of I/O primitives, and do not mandate that they do > thread synchronization. Do you think they should crash when used from two threads at once? I don't think that this acceptable for *any* Guile data structure. >>> However, if we promise to do thread synchronization, we will condemn >>> Guile to forever having dog slow 'read-char', 'peek-char', 'write-char', >>> 'get-u8', 'peek-u8', and 'put-u8' operations. >> >> I think you are wrong about "dog slow". Uncontended mutexes are fast, > > I did some benchmarks of 'putchar' vs 'putchar_unlocked' in C, without > contention. I think it's fair to assume that the GCC and GLIBC folks > did a reasonably good job of making both of these as fast as they could. > > With gcc -O2, I tested two variants of this program: one with 'putchar' > and one with 'putchar_unlocked'. On my YeeLoong (mips64el w/ N32 ABI), > the 'putchar_unlocked' version is faster by a factor of 26.3. On my i7-2620M, the difference is only a factor of 3.0. Now I think I understand your perspective; 26x is terrible. But surely this is an architecture problem, and not a Guile problem? The world will only get more multithreaded, and ignoring that does no one any service. > Finally, robust programs will have to do their own explicit > synchronization anyway. Multiple threads writing to the same port > without explicit synchronization would lead to garbled output that is > interleaved at unspecified points. The situation is even worse on the > read side. > > In order to do proper I/O on the same port from multiple threads, the > locking _must_ be done within code that understands the meaning of the > data being read or written, because only such code can know where the > data can be interleaved without producing garbage. This is a good point but not germane to the crashing issue. Andy -- http://wingolog.org/