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