I'm pretty new to this, too, but this is what I've picked up.
An object can be implicitly locked for the duration of a method by the definition syntax:
sub some_method : method : locked {
my $self = shift;
# ...
}
See attributes.
By default in 5.8 ithreads, variables are not shared and no locking is needed. Each thread has its own copy of the variables. See threads. If you want shared variables you need to use threads::shared; which makes the shared attribute available, and provides share() to set the attribute at runtime and lock() to hold it stable.
Sharing reaches one reference level deep, so you can lock a reference $foo = \@foo with share(\$foo) and avoid locking the underlying structure. For objects, share($foo) locks the @foo array, too.
The perlthrtut doc is a great way to get started with this stuff. I quote from it:
If you have experience with other thread implementations, you might find that things aren't quite what you expect. It's very important to remember when dealing with Perl threads that Perl Threads Are Not X Threads, for all values of X. They aren't POSIX threads, or DecThreads, or Java's Green threads, or Win32 threads. There are similarities, and the broad concepts are the same, but if you start looking for implementation details you're going to be either disappointed or confused. Possibly both.
After Compline, Zaxo
| [reply] [d/l] |