fibers and ranges: what's wrong here?

Tobias Pankrath via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Dec 13 04:15:36 PST 2014


When you assigning the worker in TreeRange, you create a delegate 
that captures the current TreeRange or 'this'.

---
      worker = new Fiber(&fiberFunc);
---

foreach is defined as 
(http://dlang.org/statement.html#ForeachStatement):

---
for (auto __r = range; !__r.empty; __r.popFront())
{
     auto e = __r.front;
     ...
}
---

__r is a copy of your range that still refers to the original 
worker which in turn refers to your original range. So when you 
popFront, the worker will advance the original range and if you 
call front you get the element from __r - unadvanced.

That's my best guess.




More information about the Digitalmars-d-learn mailing list