Sampo Kellomaki writes:
>I'm a bit new to threaded perl, but I have noticed following
>obstacles in writing thread safe code for perl
> * file handles can't be made "my"
Incorrect. perldoc Filehandle.
> * local variables can not be safely used in threaded code
> (another thread can unexpectedly unlocalize your local
> variable in middle of a basic block)
I confess that I'm not sure how local variables work in threads; by
all rights, they -should- be semaphored, but I don't know that they
are.
> * behaviour of magic variables is not well defined
Sure it is. You can localize them (and they are automagically
localized when appropriate), but can't create lexical variables with
their names.
>, e.g. $_ can't be made "my" but its used by many very important
> perl constructs, such as map and grep.
A decent, but not great workaround would be to -always- create
lexical placeholders for magic variables, ie @foobar=map {my ($foo)=$_;
$foo=~s/f/b/gi; $foo } @bar.
But in general, separate local variables with the same name
should not bash each other in threads. I don't know that this is how
things actually work.
> must be magically thread safe (although $_ can't be made
> local?!?)
It can too.
--
Joshua Kronengold ([EMAIL PROTECTED]) |\ _,,,--,,_ ,)
---^---- /,`.-'`' -, ;-;;'
/\\ "What part of 'Pthhhrrrrrrrrrrrrrrrrrr' |,4- ) )-,_ ) /\
-/-\\\-- didn't you understand?" '---''(_/--' (_/-'