Parallel ranges, how?

Simen kjaeraas simen.kjaras at gmail.com
Sun May 30 13:59:15 PDT 2010


Simen kjaeraas <simen.kjaras at gmail.com> wrote:

> How does the current range system accommodate parallel iteration?
>
> As far as I can see, a context switch could happen between calls to
> popFront and front, thus popping a value off the range before we're
> able to get its value.

Anyone? It seems to me the system is not thread-safe, and a parallel
range should have the functions lock() and unlock(), so a foreach
would work basically like this:

foreach( e; r ) {
   stuff(e);
}
=>
while(true) {
     r.lock();
     if (r.empty) {
         unlock();
         break;
     }
     auto e = r.front;
     r.popFront();
     r.unlock();

     stuff(e);
}

Note that this approach does not in any way protect access to the
elements, only the range functions.

-- 
Simen


More information about the Digitalmars-d-learn mailing list