Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am writing a multithreaded Perl script and I want all threads to have access to an instance of the Algorithm::NaiveBayes classifier.
So my code goes like this:and then $nb gets passed to the subroutine being run by each thread. However, at run time I getting the error about value not valid for shared scalar and it points to the line where I initialize $nb. I read on other threads that the shared model of Perl can only make shareable simple objects like hash and list, and can only go down one level deep if these are nested.my $nb : shared; $nb = Algorithm::NaiveBayes->new();
So, in light of this restriction is it possible to have several threads somehow share an instance of NaiveBayes? The reason I don't want each thread having separate private copy of $nb is that the trained model is quite large (~1GB) so it's a waste of memory to replicate it N times. The model is only accessed for classification and no changes are made to it (read-only) by any of the threads. So it seems like prime candidate for sharing. But I can't get it to work. Any thoughts/suggestions?
Thanks in advance.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: shared complex scalars between threads
by BrowserUk (Patriarch) on Oct 15, 2008 at 23:45 UTC | |
by gone2015 (Deacon) on Oct 16, 2008 at 00:17 UTC | |
by BrowserUk (Patriarch) on Oct 16, 2008 at 01:32 UTC | |
by Anonymous Monk on Oct 16, 2008 at 15:24 UTC | |
by BrowserUk (Patriarch) on Oct 16, 2008 at 15:53 UTC | |
Re: shared complex scalars between threads
by Illuminatus (Curate) on Oct 15, 2008 at 21:30 UTC | |
Re: shared complex scalars between threads
by aufflick (Deacon) on Oct 15, 2008 at 23:50 UTC |