Bug 16249 – std.signals: disconnect() is unsafe during emit()

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-07-07T16:51:00Z
Last change time
2017-01-07T03:02:09Z
Keywords
pull
Assigned to
nobody
Creator
nmtigor.wang

Comments

Comment #0 by nmtigor.wang — 2016-07-07T16:51:18Z
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().
Comment #1 by nmtigor.wang — 2016-07-07T22:27:44Z
Comment #2 by github-bugzilla — 2016-10-16T19:52:02Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/92eb63547953af2e6514a0fa6c9e109f70643b1b fix issue 16249 - std.signals: disconnect() is unsafe during emit() https://github.com/dlang/phobos/commit/910681ccc97df490871075c6dee6d8ae5db2d298 Merge pull request #4574 from nmtigor/issue_16249 fix issue 16249 - std.signals: disconnect() is unsafe during emit()
Comment #3 by github-bugzilla — 2017-01-07T03:02:09Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/92eb63547953af2e6514a0fa6c9e109f70643b1b fix issue 16249 - std.signals: disconnect() is unsafe during emit() https://github.com/dlang/phobos/commit/910681ccc97df490871075c6dee6d8ae5db2d298 Merge pull request #4574 from nmtigor/issue_16249