digitalmars.D.learn - Passing class references between threads
- Nick Gurrola (12/12) Jun 22 2012 I'm trying to figure out how to pass a class reference between
- =?UTF-8?B?QWxleCBSw7hubmUgUGV0ZXJzZW4=?= (8/19) Jun 22 2012 Cast it to shared and cast shared away in the other thread. It's not
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
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