Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl: Are Special Variables Thread Safe?

I was reading some questions regarding the $@ global variable and how it can be clobbered before it's even handled due to successful evals wiping it clean.

But what if it gets clobbered by an error occurring in a concurrent thread? The new threads package says stuff isn't shared by default, which means it's one of the few mainstream languages that makes '$a = $a;' deterministic by default (and to think that people say C# and Java are better than Perl in large projects). But I'm not sure about special global variables.

My gut's instinct says they're just like any other variable, thus they won't be shared. My brain's instinct says 'let's check with the wizards on Stackoverflow'.

I checked the threading tutorial on Perldoc, and it covers normal variables in the sharing section, but then seems to move on without covering special variables.

Can I use the special variables without risk of them being clobbered by other threads, even if I don't localize them first? E.g. can I pull a value out of $@ without worrying about errors occurring in parallel threads?

like image 504
Louis Avatar asked Jul 19 '11 20:07

Louis


1 Answers

your guts are right, they are not shared!

like image 56
salva Avatar answered Oct 06 '22 16:10

salva