forked from Perl/perl5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't end up in global locale upon thread destruction
The POSIX 2008 locale API introduces per-thread locales. But the previous global locale system is retained, probably for backward compatibility. Prior to this commit, there was a bug in which, when a thread terminates, the master thread was switched into the global locale. That meant that that thread was no longer thread-safe with regards to locales. This bug stems from the fact that perl assumes that all you need to do to switch between threads (or embedded interpreters) is to change out aTHX. Indeed much effort was expended in crafting perl to make this the case. But it breaks down in the case of some alien library that keeps per-thread information. That library needs to be informed of the switch. In this case it is libc keeping per-thread locale information. We change the thread context, but the library still retains the old thread's locale. One cannot be using a given locale object and successfully free it. Therefore the code switches to the global locale (which isn't deletable) before freeing. There was no apparent need to do more switching, as the thread is in the process of dying. What I was unaware of is that it is the parent thread pretending to be the dying one for the purposes of destruction. So switching to the global locale affected the parent, leaving it there. The parent thread called the locale.c thread locale termination function, and then called the perl.c perl_destruct() on the thread. This commit moves all the code for thread destruction from perl.c into the locale.c code, and calls it. Thus the thread initiation and termination is moved into locale.c The thread termination is also called from thread.c. This cleans up a dying thread. The perl.c call is needed for thread0 and non-multiplicity builds. A check is done to prevent duplicate work. This commit adds a new per-interpreter variable which maps aTHX to its locale. This is used to get the terminating thread's locale instead of the master. And the master locale is switched back to at the end. This commit is incomplete. Something similar needs to be done for Windows where the libc knows the per-thread locale. I'm unsure of if this is the full correct approach. It only works for thread termination. Perhaps a better solution would be to change the locale every time aTHX is changed. PERL_SET_INTERP, PERL_SET_CONTEXT, and PERL_SET_THX all seem to do the aTHX change, and I can't figure out when you would prefer one over the other. But maybe one of them should then arrange also to change the locale when aTHX is changed. Perhaps you can think of other libraries and functions that have a similar problem that also would need something like this. This commit causes Perl#20155 to go away. The triggering failure is merely a symptom of the deeper problem. A proper test will need to be done in XS.
- Loading branch information
1 parent
7867531
commit 3c10fd8
Showing
8 changed files
with
98 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters