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