Summary: Wrong code when updating struct member value from
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from David Simcha <> 2010-09-02 20:31:20 PDT ---
This is a test case produced from an experiment with converting opApply to
ranges using fibers:

import core.thread, std.traits, std.range, std.stdio;

struct OpApplyToRange(Iterable) {
    Fiber fiber;
    ForeachType!Iterable _front;
    Iterable iterable;

    void doLoop() {
        stderr.writeln("_front's address from fiber:  ", &_front);
        foreach(elem; iterable) {
            stderr.writefln("Assigning %s to front", elem);
            _front = elem;
            stderr.writeln("_front has value ", _front);
            stderr.writeln("Resumed with value ", _front);

        stderr.writeln("doLoop done.");

    this(Iterable iterable) {
        this.iterable = iterable;
        fiber = new Fiber(&doLoop);;

    void popFront() {;

void main() {
    auto oar = OpApplyToRange!(int[])([1,2,3]);
    stderr.writeln("_front's address from main:  ", &oar._front);

    foreach(i; 0..3) {
        stderr.writeln("Calling fiber sees:  ", oar._front);

_front's address from fiber:  18FE34
Assigning 1 to front
_front has value 1
_front's address from main:  18FE24
Calling fiber sees:  1
Resumed with value 1
Assigning 2 to front
_front has value 2
Calling fiber sees:  1
Resumed with value 2
Assigning 3 to front
_front has value 3
Calling fiber sees:  1
Resumed with value 3
doLoop done.

Apparently the same variable somehow has a different address when viewed from
the main thread vs. fron a fiber, leading to some rather interesting
consequences, like updates made from the fiber not being visible in the main
function. (??????????)

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to