Static problem

Stanislav Blinov stanislav.blinov at gmail.com
Thu Oct 7 12:33:54 PDT 2010


Bob Cowdery wrote:
>  Can someone sort out what I'm doing wrong here please.
> -------------
> import std.concurrency, std.stdio;
> import Definitions.procNames;
> 
> class CRegistry {
>     static Tid[E_PROC] TidRegistry;
> 
>     static void register(E_PROC name, Tid tid) {
> 
>         writeln(TidRegistry);
>         TidRegistry[name] = tid;
>     }
> 
>     static Tid getTid(E_PROC name) {
> 
>         //writeln("Entries: ", TidRegistry);
>         if(name in TidRegistry) {
>             writeln ("Returning ,", TidRegistry[name], " for " , name);
>             return TidRegistry[name];
>         }
>         return thisTid();
>     }
> }
> --------------
> 
> I register TID's like so:
> CRegistry.register(E_PROC.HPSDR, hpsdr_tid);
> and get them like so:
> CRegistry.getTid(E_PROC.HPSDR);
> 
> If I call getTid() from any another module other than the one than set
> the values, TidRegistry is empty. How do I share this registry between
> modules.
> 
> Thanks
> bob
> 
>


Could you please post the use case as well? It should matter not from 
what module you make the calls, as long as those calls are from the same 
thread. Different threads get different copies of the registry.


More information about the Digitalmars-d-learn mailing list