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