www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Passing class references between threads

reply "Nick Gurrola" <ngurrola17 gmail.com> writes:
I'm trying to figure out how to pass a class reference between 
threads. I'm using the new std.process and want to wait for the 
process to exit in a separate thread while storing a reference to 
the ProcessPipes, but D won't let you pass non-shared mutable 
data. The reference can't be immutable, so is there any way to 
make it shared without altering the class definition? Here is the 
code:

pipes = pipeProcess(runCommand);
spawn(&waitProcess, pipes);

pipes is in the class definition as

ProcessPipes pipes;

How could I do this?
Jun 22 2012
parent =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= <alex lycus.org> writes:
On 23-06-2012 05:48, Nick Gurrola wrote:
 I'm trying to figure out how to pass a class reference between threads.
 I'm using the new std.process and want to wait for the process to exit
 in a separate thread while storing a reference to the ProcessPipes, but
 D won't let you pass non-shared mutable data. The reference can't be
 immutable, so is there any way to make it shared without altering the
 class definition? Here is the code:

 pipes = pipeProcess(runCommand);
 spawn(&waitProcess, pipes);

 pipes is in the class definition as

 ProcessPipes pipes;

 How could I do this?

Cast it to shared and cast shared away in the other thread. It's not pretty, but shared isn't the silver bullet that the designers of D2 like to think that it is. -- Alex Rønne Petersen alex lycus.org http://lycus.org
Jun 22 2012