How do I break from loop when using parallel()?

Russel Winder russel at winder.org.uk
Tue May 29 19:17:50 UTC 2018


On Mon, 2018-05-28 at 21:04 +0000, Dr.No via Digitalmars-d-learn wrote:
> 		import std.parallelism : parallel;
> 		foreach(t; parallel(arr))
> 		{
> 			if(!doSomething(t)) {
> 				return false;
> 			}
> 		}
> 
> It reuturns the run time error:
> 
> > std.parallelism.ParallelForeachError@(0): Cannot break from a 
> > parallel foreach loop using break, return, labeled 
> > break/continue or goto statements.
> 
> What's the proper way to break from loop?

It isn't a loop, it is a task scatter/gather, with each task running to
completion independent of all other tasks. Thus the concept of
break/return doesn't exist.

It could be argued that this is a bad use of foreach, but it is what it
is.

-- 
Russel.
===========================================
Dr Russel Winder      t: +44 20 7585 2200
41 Buckmaster Road    m: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20180529/4dc01c6d/attachment.sig>


More information about the Digitalmars-d-learn mailing list