Skip to content

Commit

Permalink
Figure out toShared.via.thread bug
Browse files Browse the repository at this point in the history
  • Loading branch information
skoppe committed Jul 22, 2021
1 parent 737f579 commit d863045
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
${{ runner.os }}-dub-
- name: Run tests
run: dub -c=unittest-release
run: dub -c=unittest-release -- -d

- name: Build
run: dub build
2 changes: 1 addition & 1 deletion source/concurrency/operations/race.d
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ struct RaceSender(Senders...) if (allSatisfy!(ApplyRight!(models, isSender), Sen
private class State(Value) : StopSource {
import concurrency.bitfield;
StopCallback cb;
shared SharedBitField!Flags bitfield;
static if (!is(Value == void))
Value value;
Exception exception;
shared SharedBitField!Flags bitfield;
bool noDropouts;
this(bool noDropouts) {
this.noDropouts = noDropouts;
Expand Down
16 changes: 15 additions & 1 deletion tests/ut/concurrency/sender.d
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ import core.atomic : atomicOp;
shared int g;

auto s = just(1)
.then((int i) @trusted shared { return g.atomicOp!"+="(1); })
.then((int i) @trusted shared { import std.stdio; auto r = g.atomicOp!"+="(1); r.writeln; return r; })
.via(ThreadSender())
.toShared();

Expand Down Expand Up @@ -223,3 +223,17 @@ import core.atomic : atomicOp;
race(delay(2.msecs).then(() shared => 2),
delay(1.msecs).then(() shared => 1)).syncWait.value.should == 1;
}

@("atomicOp")
@safe unittest {
import concurrency.operations.toshared;
import std.stdio;

shared int g;

auto s = justFrom(() @trusted shared => g.atomicOp!"+="(1))
.via(ThreadSender());

whenAll(s,s,s,s,s,s,s,s,s,s).syncWait.assumeOk;
g.should == 10;
}

0 comments on commit d863045

Please sign in to comment.