in reply to Re^2: Thread-safe modules and callbacks
in thread Thread-safe modules and callbacks
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:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Thread-safe modules and callbacks
by Saladino (Beadle) on May 10, 2008 at 09:53 UTC | |
by BrowserUk (Patriarch) on May 10, 2008 at 13:52 UTC | |
by Saladino (Beadle) on May 10, 2008 at 14:25 UTC | |
by BrowserUk (Patriarch) on May 10, 2008 at 15:03 UTC | |
by Saladino (Beadle) on May 10, 2008 at 15:13 UTC | |
|