It depends upon what you're trying to achieve.
{ my $n = 0; sub handler { my $tid = threads->self->tid; for( 1 .. 5e5 ) { usleep( 100 ); print "$tid: ", $n++; } } }
Each handler will get it's own copy of $n above and can use it without concerns for locking or sharing. It retains it's value across calls to the handler.
Isolating your users from the requirements of shared data is possible, but distinctly non-trivial.
I am reluctant to expend energy describing possible approached until I:
In reply to Re^3: Thread-safe modules and callbacks
by BrowserUk
in thread Thread-safe modules and callbacks
by Saladino
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |