parallel
    anonymous via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Thu Nov  5 12:54:36 PST 2015
    
    
  
On 05.11.2015 21:43, Handyman wrote:
> foreach (i; 0..50)
>     Thread.sleep(20.msecs);
>
> But then my program still says: '2 secs'.   Please enlighten me.
Let's look at the line that does the `parallel` call:
     foreach (dish; parallel(dishes, 1)) dish.prepare();
This means that `dishes` is processed in parallel. Multiple threads are 
started to execute `prepare()` on multiple elements of `dishes` at the 
same time.
Each of those `dish.prepare()` calls is done on only one thread, though. 
There is not attempt to split the `prepare` action up and run parts of 
it in parallel.
    
    
More information about the Digitalmars-d-learn
mailing list