[Issue 4790] New: Wrong code when updating struct member value from fiber
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Sep 2 20:31:37 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4790
Summary: Wrong code when updating struct member value from
fiber
Product: D
Version: D2
Platform: Other
OS/Version: Windows
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: dsimcha at yahoo.com
--- Comment #0 from David Simcha <dsimcha at yahoo.com> 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);
Fiber.yield();
stderr.writeln("Resumed with value ", _front);
}
stderr.writeln("doLoop done.");
}
this(Iterable iterable) {
this.iterable = iterable;
fiber = new Fiber(&doLoop);
fiber.call();
}
void popFront() {
fiber.call();
}
}
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);
oar.popFront();
}
}
_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: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list