Right way to share object through threads

Andrea Fontana nospam at example.com
Thu May 10 04:12:59 PDT 2012


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?


More information about the Digitalmars-d-learn mailing list