dd8638
From a0eaa97e59b5b2ad8e2a83f8509da3787ff4b4bf Mon Sep 17 00:00:00 2001
dd8638
From: Jitka Plesnikova <jplesnik@redhat.com>
dd8638
Date: Thu, 24 May 2018 11:32:01 +0200
dd8638
Subject: [PATCH] Upgrade to 2.22
dd8638
dd8638
---
dd8638
 lib/threads.pm | 29 ++++++++++++++++++++++++++++-
dd8638
 threads.xs     |  4 ++++
dd8638
 2 files changed, 32 insertions(+), 1 deletion(-)
dd8638
dd8638
diff --git a/lib/threads.pm b/lib/threads.pm
dd8638
index 2eb926a..1b99567 100644
dd8638
--- a/lib/threads.pm
dd8638
+++ b/lib/threads.pm
dd8638
@@ -5,7 +5,7 @@ use 5.008;
dd8638
 use strict;
dd8638
 use warnings;
dd8638
 
dd8638
-our $VERSION = '2.21';      # remember to update version in POD!
dd8638
+our $VERSION = '2.22';      # remember to update version in POD!
dd8638
 my $XS_VERSION = $VERSION;
dd8638
 $VERSION = eval $VERSION;
dd8638
 
dd8638
@@ -937,6 +937,33 @@ C<chdir()>) will affect all the threads in the application.
dd8638
 On MSWin32, each thread maintains its own the current working directory
dd8638
 setting.
dd8638
 
dd8638
+=item Locales
dd8638
+
dd8638
+Prior to Perl 5.28, locales could not be used with threads, due to various
dd8638
+race conditions.  Starting in that release, on systems that implement
dd8638
+thread-safe locale functions, threads can be used, with some caveats.
dd8638
+This includes Windows starting with Visual Studio 2005, and systems compatible
dd8638
+with POSIX 2008.  See L<perllocale/Multi-threaded operation>.
dd8638
+
dd8638
+Each thread (except the main thread) is started using the C locale.  The main
dd8638
+thread is started like all other Perl programs; see L<perllocale/ENVIRONMENT>.
dd8638
+You can switch locales in any thread as often as you like.
dd8638
+
dd8638
+If you want to inherit the parent thread's locale, you can, in the parent, set
dd8638
+a variable like so:
dd8638
+
dd8638
+    $foo = POSIX::setlocale(LC_ALL, NULL);
dd8638
+
dd8638
+and then pass to threads->create() a sub that closes over C<$foo>.  Then, in
dd8638
+the child, you say
dd8638
+
dd8638
+    POSIX::setlocale(LC_ALL, $foo);
dd8638
+
dd8638
+Or you can use the facilities in L<threads::shared> to pass C<$foo>;
dd8638
+or if the environment hasn't changed, in the child, do
dd8638
+
dd8638
+    POSIX::setlocale(LC_ALL, "");
dd8638
+
dd8638
 =item Environment variables
dd8638
 
dd8638
 Currently, on all platforms except MSWin32, all I<system> calls (e.g., using
dd8638
diff --git a/threads.xs b/threads.xs
dd8638
index 4e9e31f..3da9165 100644
dd8638
--- a/threads.xs
dd8638
+++ b/threads.xs
dd8638
@@ -580,6 +580,8 @@ S_ithread_run(void * arg)
dd8638
     S_set_sigmask(&thread->initial_sigmask);
dd8638
 #endif
dd8638
 
dd8638
+    thread_locale_init();
dd8638
+
dd8638
     PL_perl_destruct_level = 2;
dd8638
 
dd8638
     {
dd8638
@@ -665,6 +667,8 @@ S_ithread_run(void * arg)
dd8638
     MUTEX_UNLOCK(&thread->mutex);
dd8638
     MUTEX_UNLOCK(&MY_POOL.create_destruct_mutex);
dd8638
 
dd8638
+    thread_locale_term();
dd8638
+
dd8638
     /* Exit application if required */
dd8638
     if (exit_app) {
dd8638
         (void)S_jmpenv_run(aTHX_ 2, thread, NULL, &exit_app, &exit_code);
dd8638
-- 
dd8638
2.14.3
dd8638