Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: a1ff7d7e0845a3d23e5dd6b27fcb73086b0f7b9c
      
https://github.com/Perl/perl5/commit/a1ff7d7e0845a3d23e5dd6b27fcb73086b0f7b9c
  Author: Karl Williamson <[email protected]>
  Date:   2026-09-20 (Sun, 20 Sep 2026)

  Changed paths:
    M perl.h

  Log Message:
  -----------
  perl.h: Use different name for calling mutex locks

The new name is the name going forward used as the basis for locks
wanting this functionality.


  Commit: 1b17aba7a4b341949204b02ad3d80e666fca9607
      
https://github.com/Perl/perl5/commit/1b17aba7a4b341949204b02ad3d80e666fca9607
  Author: Karl Williamson <[email protected]>
  Date:   2026-09-20 (Sun, 20 Sep 2026)

  Changed paths:
    M perl.h

  Log Message:
  -----------
  Fix PERL_GENr_ENVr_LCx_LOCK definition

The previous definition was discarding that it needed an exclusive lock.
This hasn't caused us any known problems in the field, but should be
fixed.


  Commit: 927117be76430fb71cdf57f6596763c99cfc70e8
      
https://github.com/Perl/perl5/commit/927117be76430fb71cdf57f6596763c99cfc70e8
  Author: Karl Williamson <[email protected]>
  Date:   2026-09-20 (Sun, 20 Sep 2026)

  Changed paths:
    M perl.h

  Log Message:
  -----------
  Remove redundant definition of gwLOCALE_LOCK

This conditionally-compiled code is overridden by a later unconditional
definition.  The compiler would have warned if they didn't currently
expand to the same thing.


  Commit: de763f7e1c876530fc233eb504bec729bcdd01a0
      
https://github.com/Perl/perl5/commit/de763f7e1c876530fc233eb504bec729bcdd01a0
  Author: Karl Williamson <[email protected]>
  Date:   2026-09-20 (Sun, 20 Sep 2026)

  Changed paths:
    M perl.h

  Log Message:
  -----------
  Fix definition of gwLOCALE_LOCK

This makes no difference in the generated code currently, but
semantically this lock means that the locale is locked for read access,
but it overwrites global storage, so the generic mutex should be locked
exclusively, and the locale one for reads


  Commit: c359b8953ce302584a52a58f469409c6dacd0e80
      
https://github.com/Perl/perl5/commit/c359b8953ce302584a52a58f469409c6dacd0e80
  Author: Karl Williamson <[email protected]>
  Date:   2026-09-20 (Sun, 20 Sep 2026)

  Changed paths:
    M perl.h
    M perl_lock_definitions.h
    M regen/lock_definitions.pl

  Log Message:
  -----------
  Prepare libc locks for thread-safe locale emulation

A future commit will add the capability to emulate thread-safe locales
on systems without them.  This is a step towards that.

The implementation will require toggling into particular locale
categories, depending on which categories the libc call uses.  That
information for each libc function is already in the <DATA> of this
file, but has remained unused until this commit.  (Note that where it
wasn't clear which locale category(ies) are used in the function, LC_ALL
is used.  Feel free in the future to tighten this.)

This commit passes the categories to the lock macro (where they remain
unused for now) and adds calls to macros that will eventually toggle and
untoggle the locale categories for the emulation


  Commit: 008136ca88636879a6c29c5f98cdfbf68b6218ce
      
https://github.com/Perl/perl5/commit/008136ca88636879a6c29c5f98cdfbf68b6218ce
  Author: Karl Williamson <[email protected]>
  Date:   2026-09-20 (Sun, 20 Sep 2026)

  Changed paths:
    M perl.h

  Log Message:
  -----------
  perl.h: Extract common #defines to common place


  Commit: 42021253f056d6fc25510068ae5ae311c528c42d
      
https://github.com/Perl/perl5/commit/42021253f056d6fc25510068ae5ae311c528c42d
  Author: Karl Williamson <[email protected]>
  Date:   2026-09-20 (Sun, 20 Sep 2026)

  Changed paths:
    M perl.h

  Log Message:
  -----------
  Prevent deadlock that future commits otherwise could cause

A future commit in this series will exercise the locale mutex (on
systems without thread-safe locales) in such a way as to cause a
recursive call to it to convert a read lock into a write lock.  That
can't be allowed because of the potential for deadlock.

This commit prevents that by making a locale read lock always instead do
an exclusive lock on such systems.


  Commit: bf889681b164b50adc6702dedd26f8e0209ca399
      
https://github.com/Perl/perl5/commit/bf889681b164b50adc6702dedd26f8e0209ca399
  Author: Karl Williamson <[email protected]>
  Date:   2026-09-20 (Sun, 20 Sep 2026)

  Changed paths:
    M perl.h

  Log Message:
  -----------
  perl.h: Temporarily remove locks debugging, panics

The next commit will revise the mutex locking scheme, and this
makes it easier to understand those changes.  The commit following that
will restore this, with heavily enhanced text.


  Commit: b5f5e25740683aa3a736248d076c20d5503564f6
      
https://github.com/Perl/perl5/commit/b5f5e25740683aa3a736248d076c20d5503564f6
  Author: Karl Williamson <[email protected]>
  Date:   2026-09-20 (Sun, 20 Sep 2026)

  Changed paths:
    M perl.h

  Log Message:
  -----------
  Revise mutex locking

A commit later in this series exercises the mutex locks much more than
currently.  Unfortunately, it showed that the current implementation can
deadlock.

I read the code, finding some issues, and also that it was somewhat more
complicated than necessary.

This commit implements the result of those findings.

Using these changes with the future commit did not deadlock.  I also ran
the valgrind tool that checks locking, and it found nothing.


  Commit: 8fd23c2b36f5a67e50ecee08f42a77f1cee9f704
      
https://github.com/Perl/perl5/commit/8fd23c2b36f5a67e50ecee08f42a77f1cee9f704
  Author: Karl Williamson <[email protected]>
  Date:   2026-09-20 (Sun, 20 Sep 2026)

  Changed paths:
    M perl.h

  Log Message:
  -----------
  Restore lock panics/debugging

This restores the error checking/debugging that was removed two commits
ago so that the one-ago commit would be clearer.  This restores them,
but with more information than before.


  Commit: e5f709e6c1ab019f318b508297c59a0d4e96c846
      
https://github.com/Perl/perl5/commit/e5f709e6c1ab019f318b508297c59a0d4e96c846
  Author: Karl Williamson <[email protected]>
  Date:   2026-09-20 (Sun, 20 Sep 2026)

  Changed paths:
    M embed.fnc
    M embed.h
    M embedvar.h
    M handy.h
    M inline.h
    M intrpvar.h
    M locale.c
    M makedef.pl
    M mg.c
    M perl.c
    M perl.h
    M pod/perlclib.pod
    M pod/perldelta.pod
    M pod/perllocale.pod
    M pod/perlvar.pod
    M proto.h
    M regen/embed.pl
    M sv.c

  Log Message:
  -----------
  Add ability to emulate thread-safe locales

Locale information was originally global for an entire process. Later,
it was realized that different threads could want to be running in
different locales. Windows added this ability, and POSIX 2008 followed
suit (though using a completely different API). When available, perl
automatically uses these capabilities.

But many platforms have neither, or their implementation, such as on
Darwin, is buggy. This commit adds the capability for Perl programs to
operate as if the platform were thread-safe.

This implementation is based on the observation that the underlying
locale matters only to relatively few libc calls, and only during their
execution. It can be anything at all at any other time. perl keeps what
the proper locale should be for each category in a a per-thread array.
Each locale-dependent operation must be wrapped in mutex lock/unlock
operations. The lock additionally compares what libc knows the locale to
be, and what it should be for this thread at this time, and changes the
actual locale to the proper value if necessary. That's all that is
needed.

When this emulation is enabled, the macros in perl.h that do mutex
locking for libc calls are changed to do the mutex lock, and change the
global locale to the expected value.  Unlocking is the reverse.

In order for XS code to also become locale-thread-safe, it definitely
must use the appropriate libc macros for it defined in
perl_lock_definitions.h.  (With native thread safety, these macros may
be no-ops, so aren't strictly required on such systems.) Relatively few
modules call such functions. For example, the only one I found that
ships with the perl core is Time::Piece, and it has more fundamental
issues with running under threads than this. I am preparing pull
requests for it.

Thus, this is not completely transparent to code like native-thread-safe
locale handling is. Therefore ${^SAFE_LOCALES} returns 2 (instead of 1)
for this type of thread-safety.

Another deficiency compared to the native thread safety is when a thread
calls a non-perl library that accesses the locale. The typical example
is Gtk (though this particular application can be configured to not be
problematic). With the native safe threads, everything works as long as
only one such thread is used per Perl program. That thread would then be
the only one operating in the global locale, hence there are no
conflicts. With this emulation, all threads are operating in the global
locale, and mutexes would have to be used to prevent conflicts. To
minimize those, the code added in this commit restores the global locale
when unlocking to the state it was in when started.

A major concern is the performance impact, trading speed for accuracy.
lib/locale_threads.t is noticeably slower when this is being used. But
that is doing multiple threads constantly using locale-dependent
operations. I don't notice any change with the rest of the test suite.
In pure perl, this only comes into play while in the scope of 'use
locale' or when using some of the few POSIX:: functions that are
locale-dependent. And to some extent when formatting, but the regular
overhead there should dwarf what this adds.

This commit leaves this feature off by default.

* This set of changes requires a perldelta entry, included.


  Commit: 5c89d29f2741502a089e1627d9f70450acb84a9c
      
https://github.com/Perl/perl5/commit/5c89d29f2741502a089e1627d9f70450acb84a9c
  Author: Karl Williamson <[email protected]>
  Date:   2026-09-20 (Sun, 20 Sep 2026)

  Changed paths:
    M embed.h
    M perl.h
    M pod/perldelta.pod
    M pod/perllocale.pod

  Log Message:
  -----------
  Temporarily enable thread-safe locale emulation

This feature is to be by default off for 5.46; but we need to test it
somehow.

This commit enables this feature for testing during the 5.45 development
cycle.  It will refuse to compile during the latter releases of the
cycle, so to make sure it gets reverted before shipping 5.46.

The feature is turned on only on threaded builds on platforms that don't
have thread-safe locales.  I'm unsure what all those are, but right now
includes all *BSD derived systems, including Darwin.  And cygwin, but
that should be fixed soon.

That doesn't include Linux (which has thread-safe locales), but when I
manually Configure for it anyway, the TEST_JOBS=37 testing on my machine
is slowed down by about 10% waiting for lib/locale_threads.t to finish.
If people complain, we can cut the number of threads or iterations when
this is enabled.


Compare: https://github.com/Perl/perl5/compare/a20f87cbe887...5c89d29f2741

To unsubscribe from these emails, change your notification settings at 
https://github.com/Perl/perl5/settings/notifications

Reply via email to