xslate / p5-Mouse

Lightweight class builder for Perl, as a subset of Moose
https://metacpan.org/release/Mouse
Other
46 stars 32 forks source link

XS Threading fix. #91

Closed sergeykolychev closed 6 years ago

sergeykolychev commented 6 years ago

Hi @skaji This change makes tests related to threads pass. Not sure why hv_fetch succeeds where hv_fetch_ent fails but it's happening only in threading tests. Without the fix

ksv@ubuntu:~/p5-Mouse$ perl -e 'use threads; package b { use Mouse; } print threads->create(sub { return b->new })->join, "\n"'
Thread 1 terminated abnormally: No package name defined for metaclass at -e line 1.

With the fix:

perl -e 'use threads; package b { use Mouse; } print threads->create(sub { return b->new })->join, "\n"'
b=HASH(0x55f6dd4c5a50)

I'll take time and investigate further, but it smells like a bug in perl itself. If possible can you ask @gfx to look at this ? Thanks in advance.

sergeykolychev commented 6 years ago

I made the change a bit verbose, the reason is that I tried to make it as less intrusive as possible and only act on the retrieval from meta that is broken in the threading environment in master branch. It seems that hv_fetch_ent is substantially faster than hv_fetch so I left it for everything else. I did run benchmarks and did not see any performance degradation.