> I've just been learning to use threads.pm and
> threads::shared.pm.
> I spent ages trying to get my script to work until I realised 
> that
>   use threads;
> must come before
>   use threads:shared;
> This probably should have been obvious from the documentation
> in threads.pm which says
>   preferably enable threads...as early as possible
> 
> I was wondering:
> - if threads could work with a simple use threads; or use
>   threads::shared;?
>   Looking at the code, it appears that they have been modified
> so
>   that they don't do this. No doubt for some very technical
>   reason beyond me (though I'd be grateful if someone could try
>   to explain), so if its not feasible, then fair enough.

Yes this is deliberate design decision. The reason is that if a module is using 
threads::shared to share a variable if running in a threaded enviroment, and the 
caller doesn't want threads we don't want to impose the overhead of shared variables.

> - if threads.pm and threads::shared.pm could have their
>   documentation amended to explicitly mention the order of the
>   'use's?
>   Given this is Perl (i.e. 'fix what you find if you can'), I'd
>   be happy to do this.

Most welcome.

> - should threads::shared.pm silently fail when there has been no
>   use threads;?
>   Again looking at the code, this appears to have been
>   deliberately designed, so if there's a good reason, then
>   ok, though this did give me a lot of grief.

Yes, it should just disable itself.
 However a good fix would be that threads::shared raises a flag and threads.pm emites 
a mandatory warning if it is loaded after threads::shared.

Warning, threads::shared has already been loaded by modules '...', to enable shared 
variables for these modules 'use threads' must be called before any of those modules 
are loaded'

> Any thoughts?
> 
> Andy Bussey
> 

Arthur

Reply via email to