unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: Mark H Weaver <mhw@netris.org>
Cc: guile-devel@gnu.org
Subject: Re: Guile's I/O procedures should *not* do thread synchronization
Date: Wed, 26 Mar 2014 09:25:34 +0100	[thread overview]
Message-ID: <878urxpds1.fsf@pobox.com> (raw)
In-Reply-To: <87vbv1ilzl.fsf_-_@yeeloong.lan> (Mark H. Weaver's message of "Wed, 26 Mar 2014 01:10:06 -0400")

On Wed 26 Mar 2014 06:10, Mark H Weaver <mhw@netris.org> writes:

> Andy Wingo <wingo@pobox.com> writes:
n>
>> On Tue 25 Mar 2014 12:14, "Diogo F. S. Ramos" <dfsr@riseup.net> writes:
>>
>>> It's not obvious that ports are not thread-safe and trying to have
>>> multiple threads writing to one returns errors that are not
>>> recognizable as been caused by this lack of thread-safeness.
>>
>> This is a bug, and it is fixed in master.  FWIW.
>
> FWIW, I disagree that this is a bug.  I continue to believe that it
> would be a very serious mistake to promise to do thread synchronization
> within Guile's standard I/O procedures.

It seems to work for glibc streams.  Why do you think that thread
synchronization is inappropriate for Guile if it works for glibc?  If
you need more speed you can disable thread synchronization.  (Admittedly
there is no API for that yet, but the possibility exists, as in libc.)

> This could be done in a future version of Guile by uniformly using a
> fixed encoding (UTF-8 or maybe UTF-32) for the port buffers of textual
> ports, and doing the coding conversion when the buffer is filled or
> flushed.

We can do this already.

> 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,
and we can disable mutexen entirely for certain ports.

> Consider string ports, for example.  They could be the basis for a very
> natural and efficient method of writing string operations, especially
> when we move to UTF-8 encoding of strings internally and string indexing
> becomes less efficient, but only if we have fast single-character I/O.

In the case of SRFI-13-style procedures with fresh string output ports,
we can avoid synchronization.  For input ports, synchronization is
really cheap as you don't ever have to rebuffer.

In summary, I think this is a non-issue.

Regards,

Andy
-- 
http://wingolog.org/



  reply	other threads:[~2014-03-26  8:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-25 11:14 [PATCH] Add observation that ports are not thread-safe Diogo F. S. Ramos
2014-03-25 14:14 ` Andy Wingo
2014-03-25 17:10   ` Diogo F. S. Ramos
2014-03-25 19:39     ` Andy Wingo
2014-03-25 20:36       ` Diogo F. S. Ramos
2014-04-15 11:24         ` Diogo F. S. Ramos
2014-03-26  5:10   ` Guile's I/O procedures should *not* do thread synchronization Mark H Weaver
2014-03-26  8:25     ` Andy Wingo [this message]
2014-03-26 15:32       ` Mark H Weaver
2014-03-26 19:45         ` Andy Wingo
2014-04-06  6:08           ` Mark H Weaver
2014-04-08 20:53             ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878urxpds1.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=guile-devel@gnu.org \
    --cc=mhw@netris.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).