Static problem

Bob Cowdery bob at bobcowdery.plus.com
Thu Oct 7 12:53:09 PDT 2010


 On 07/10/2010 20:33, Stanislav Blinov wrote:
> 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.
I suspected that might be the case. Yes they are from separate threads.
No conflict as one writes all the tids and the others only read them.
What's the best way to fix that?



More information about the Digitalmars-d-learn mailing list