bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: bug-gnulib@gnu.org
Subject: Re: single-threaded optimizations
Date: Sun, 07 Mar 2021 10:58:28 +0100	[thread overview]
Message-ID: <2783771.9LmcWK8fO3@omega> (raw)
In-Reply-To: <d1e2ddb3-def3-c0d5-d332-e6f18c84e19f@cs.ucla.edu>

Hi Paul,

> > a general macro won't cut it e.g. for coreutils. coreutils
> > has multithreaded programs ('sort') next to single-threaded programs.
> > But coreutils wants to optimize wcwidth. GNULIB_WCHAR_SINGLE actually
> > means "assume that the locale has been set before the program becomes
> > multithreaded, and won't change afterwards". Similarly,
> > '#include "unlocked-io.h"' does not mean that the program is single-
> > threaded; it means that no FILE object is being accessed in more than
> > one thread.
> 
> Good point. How about this idea?
> 
> * We establish a new macro GNULIB_MBTOWC_SINGLE which means "assume that 
> at most one thread invokes mbtowc-like functions". The mbtowc 
> replacement uses this instead of using USE_UNLOCKED_IO. Tar can #define 
> this new macro.

I like this idea. The packages can then define or not define each such
macro individually.

> * If macros like GNLIB_MBTOWC_SINGLE proliferate, we can have a single 
> macro GNULIB_SINGLE_THREADED that implies all the other macros. For now 
> I'm not sure it's worth the bother to do this.

I agree, it doesn't seem worth to have such a GNULIB_SINGLE_THREADED
macro because
  - more code becomes multithreaded over time,
  - the documentation clearly states what each of the individual macros
    imply.

> * If someone has the time, fix the underlying problem that the Gnulib 
> mbrtowc replacement doesn't link under AIX in some circumstances, unless 
> you #define GNULIB_MBTOWC_SINGLE.

The mbrtowc modules states:

  Link:
  $(LIB_MBRTOWC)

This link dependency (which expands to -lpthread on AIX) is needed because
we document that

  This function does not put the state into non-initial state when parsing an
  incomplete multibyte character on some platforms:
  AIX 7.2.

and
  - Since the state of mbrtowc is hidden, we cannot work around this without
    reimplementing mbrtowc from scratch.
  - Since the wide character representation on AIX is locale dependent and
    undocumented, we cannot roll our own mbrtowc implementation, but must use
    mbtowc().
  - mbtowc() uses global state and is therefore not multithread-safe.

> I think I 
> might want to investigate the possibility of having the mbrtowc 
> replacement use AIX mbrtowc instead of a lock around AIX mbtowc, as that 
> should perform better anyway. But I'm not sure AIX is worth the time for 
> this sort of thing.

I don't know what the solution could look like.

Bruno



  reply	other threads:[~2021-03-07  9:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-03  0:28 [PATCH] mbrtowc: port to AIX 7.1 with xlc 12.1 Paul Eggert
2021-03-03  3:27 ` single-threaded optimizations Bruno Haible
2021-03-06 16:56   ` Paul Eggert
2021-03-07  9:58     ` Bruno Haible [this message]
2021-03-07 10:03       ` Bruno Haible
2021-03-08  2:46       ` Paul Eggert

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://lists.gnu.org/mailman/listinfo/bug-gnulib

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

  git send-email \
    --in-reply-to=2783771.9LmcWK8fO3@omega \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=eggert@cs.ucla.edu \
    /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).