Right way to share object through threads

sclytrack sclytrack at iq87.fr
Thu May 10 04:42:43 PDT 2012


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)();


More information about the Digitalmars-d-learn mailing list