digitalmars.D.learn - Right way to share object through threads
- Andrea Fontana (16/16) May 10 2012 I can't understand which is the right way to share MyClass thru
- sclytrack (2/16) May 10 2012 new shared(MyClass)();
- Andrea Fontana (2/29) May 10 2012 Thank you! I didn't know this syntax!
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?
May 10 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)();
May 10 2012
On Thursday, 10 May 2012 at 11:42:44 UTC, sclytrack wrote:On 05/10/2012 01:12 PM, Andrea Fontana wrote:Thank you! I didn't know this syntax!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)();
May 10 2012








"Andrea Fontana" <nospam example.com>