Passing class references between threads
Alex Rønne Petersen
alex at lycus.org
Fri Jun 22 20:51:39 PDT 2012
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 at lycus.org
http://lycus.org
More information about the Digitalmars-d-learn
mailing list