spawn X different workers & wait for results from all of them

Robert M. Münch via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Sep 5 03:21:33 PDT 2015


On 2015-09-04 17:32:48 +0000, Justin Whear said:

> How would receive know?

Well, it could be pretty simple. At the moment:

receive(
	int ...,
	long ...,
	myStruct ...
)

Will wait for one out of the three. So it's an OR.

reveive_all(
	int ...,
	long ...,
	myStruct ...
)

would finish if every type was returned once (maybe at least once). 
With this I would have an AND combination.

> If you're using std.concurrency, the receiving
> function needs to encode doneness, e.g.
> 
> const numJobs = 4;
> foreach (_; 0 .. numJobs)
> 	receive(...);

That's what you can do if the type is the same. Or just put four 
receives sequentially in the code. The not so nice side effect is, that 
you define an order for processing but the tasks might finish in an 
other order. So, possible work is blocked.

> Or you could use std.parallelism:
> 
> foreach (pieceOfWork; parallel(listOfWork))
> 	doIt(pieceOfWork);

My "pieceOfWork" is not the same. So I don't have the case: Do 4 time 
this 1thing. Instead, do 1 time these 4 things.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



More information about the Digitalmars-d-learn mailing list