This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_my_cxt_init: fix potential race condition
(Found by code inspection - I can't reproduce a failure)
the MY_CXT subsystem, which allows per-thread pseudo-static variables,
has a thread race condition.
When a module is first loaded, it is allocated unique index (from
PL_my_cxt_index++) which is assigned to the module's my_cxt_index static
var.
If two threads both try to load an XS module at the same time, its
possible for one thread to set my_cxtp, then a second thread to overwrite
it with a higher value, causing the first thread to use the wrong index
into its local storage.