[Issue 16249] New: std.signals: disconnect() is unsafe during emit()
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Jul 7 09:51:18 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16249
Issue ID: 16249
Summary: std.signals: disconnect() is unsafe during emit()
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: nmtigor.wang at googlemail.com
Hello,
conisder the following code:
============================
module dtest;
import std.signals;
struct SIGLine
{
myLINE line;
int value;
}
class myLINE
{
mixin Signal!SIGLine;
void value(int v)
{
if (v >= 0)
emit(SIGLine(this, v));
else
emit(SIGLine(new myLINE, v));
}
}
class Dot
{
int value;
myLINE line_;
void line(myLINE line_x)
{
if (line_ is line_x)
return;
if (line_ !is null)
{
line_.disconnect(&watch);
}
line_ = line_x;
line_.connect(&watch);
}
void watch(SIGLine sigline)
{
line = sigline.line;
value = sigline.value;
}
}
@system unittest
{
auto dot1 = new Dot;
auto dot2 = new Dot;
auto line = new myLINE;
dot1.line = line;
dot2.line = line;
line.value = 11;
assert(dot1.value == 11);
assert(dot2.value == 11);
line.value = -22;
assert(dot1.value == -22);
assert(dot2.value == -22); // ERROR
}
============================
The error is because slots_idx is changed during the loop in emit().
--
More information about the Digitalmars-d-bugs
mailing list