Right way to share object through threads
Andrea Fontana
nospam at example.com
Thu May 10 05:37:38 PDT 2012
On Thursday, 10 May 2012 at 11:42:44 UTC, sclytrack wrote:
> On 05/10/2012 01:12 PM, Andrea Fontana wrote:
>> I can't understand which is the right way to share MyClass
>> thru threads.
>>
>> MyClass performs a lot of operation during init (it has to
>> parse a lot
>> of data). After this long init, it runs very fast operations
>> so I want
>> to build it just one time and use it on different threads.
>>
>> Declaring it as a global object in this way:
>>
>> class MyClass
>> {
>> this() {}
>> }
>>
>> shared MyClass test;
>>
>> when i try to use contructor, dmd says:
>>
>> Error: cannot implicitly convert expression (new MyClass) of
>> type
>> test.MyClass to shared(MyClass)
>>
>> Which is the right way to implement it?
>
> new shared(MyClass)();
Thank you! I didn't know this syntax!
More information about the Digitalmars-d-learn
mailing list