This brings up the next big issue you will face, and that is thread code being repeatedly called, can cause a memory gain, ...
When was the last time you observed this behaviour?
Running the following snippet for 10,000 thread creation/death cycles, the memory bobs up and down (under win32 thread local memory gets returned to the system). The memory usage fluctuates between 7.4MB and 11.3 MB and ends at 7.1 MB just before it ends.
So there is no obvious pattern of growth (and no big issue I can see), despite the closures, under 5.8.6 or 5.8.8. I haven't tried it under 5.9.x yet.
If you could post code,or modify that below, to demonstrated the problem ?
#! perl -slw use strict; use threads; use threads::shared; our $N ||= 1000; our $aClonedGlobal = 12345; my $aClonedLexical = 12345; our $aSharedGlobal :shared = 12345; my $aSharedLexical :shared = 12345; my $running :shared = 0; for ( 1 .. $N ) { async{ { lock $running; ++$running } my $tid = threads->self->tid; my( $some, $thread, $local, $vars ) = (12345) x 4; require Carp; require IO::Socket; require Time::HiRes; print "$tid: $aClonedGlobal : $aClonedLexical : $aSharedGlobal + : $aSharedLexical"; { lock $running; --$running }; }->detach; } sleep 1 while $running;
A final point, changes in shared variable's values are not automatically seen between threads. Each thread needs to run a timer or loop to constantly check them.
I don't understand what you mean by this? Shared vars are tied. Every time you reference one, the current value is retrieved from the master copy. How can "changes ... not [be] automatically seen between threads.", unless you reference them?
May be I am missing something? Again, could you post an example to demonstrate what you mean by this please?
In reply to Re^2: Threads question
by BrowserUk
in thread Threads question
by xiaoyafeng
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |