pass array of objects to spawn

Ruslan Mullakhmetov tiabaldu at gmail.com
Thu Nov 10 13:57:00 PST 2011


On 2011-11-11 01:21:09 +0400, Ali Çehreli said:

> class Foo
> {
> 
> }
> 
> void worker( shared(Foo)[] data )
> {
>      //...
> }
> 
> void main()
> {
>      auto data = new shared(Foo)[10];
>      spawn( &worker, data );
> }


Thanks. I tried to use the second version, a lttle bit modified it for 
actual mutation and it is failed to compile with error

thread.d(17): Error: function thread.Foo.mutate () is not callable 
using argument types () shared


the code:

import std.exception;
import std.concurrency;

class Foo
{
	public int val;
	
	void mutate()
	{
		val = 1;
	}
}


void worker( shared(Foo)[] data )
{
	data[0].mutate();
     //...
}

void main()
{
     auto data = new shared(Foo)[10];
     spawn( &worker, data );
}


-- 
BR, Ruslan Mullakhmetov



More information about the Digitalmars-d-learn mailing list