develooper Front page | perl.perl5.porters | Postings from September 2022

khw needs some help about threads and embedded perls

Thread Next
From:
Karl Williamson
Date:
September 4, 2022 15:24
Subject:
khw needs some help about threads and embedded perls
Message ID:
e563603e-7d55-061b-fa78-c1e5e6eaf258@khwilliamson.com
#20178 exposed a non-trivial problem with locale handling in threaded 
perls.  And there may be other operations affected as well.

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 is buggy: it 
breaks down in the case of some library that keeps per-thread 
information and is not party to the protocol. That library needs to be 
informed when a switch is made.  libc is one example of this with 
regards to POSIX 2008 locale functions, and Windows as well  I imagine 
there are other similar issues.  Please think about it for a minute. 
What other libc functionality is per-thread and persistent between 
calls?  What about in other common libraries?

I am uncertain how to fix this with regard to locales.  The switching 
could be changed so as to switch the locale every time the thread 
context is changed.  But there are several ways to do this. There are 
three macros in perl.h that change aTHX:  PERL_SET_INTERP, 
PERL_SET_CONTEXT, and PERL_SET_THX. Currently, they all resolve to 
PERL_SET_INTERP, but it looks like that is designed to be overridable, 
and it isn't documented. PERL_SET_CONTEXT is the only documented one.

And threads.h overrides PERL_SET_CONTEXT to use the POSIX 
thread_specific functions.

Can someone shed light on the design of these?

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About