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
authorDavid Mitchell <davem@iabyn.com>
Mon, 18 Feb 2019 09:19:38 +0000 (09:19 +0000)
committerDavid Mitchell <davem@iabyn.com>
Tue, 19 Feb 2019 13:28:12 +0000 (13:28 +0000)
commit61d4c87c940fea028f08f27addc275b469320fda
tree2b3ec59900f4afb0db365dc392699b335b6922bf
parent6009fde9e4e3d825057f663d300a7bede478e5c3
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.
util.c