Skip to content

Commit b9ee090

Browse files
committed
Add tsan edges when actors transition in and out of running state.
1 parent 79fb05b commit b9ee090

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,8 @@ void DefaultActorImpl::giveUpThread(RunningJobInfo runner) {
929929
// Try again.
930930
continue;
931931
}
932+
_swift_tsan_release(this);
933+
932934
#if SWIFT_TASK_PRINTF_DEBUG
933935
# define LOG_STATE_TRANSITION fprintf(stderr, "%p transition from %zx to %zx in %p.%s\n", \
934936
pthread_self(), oldState.Flags.getOpaqueValue(), newState.Flags.getOpaqueValue(), this, __FUNCTION__)
@@ -1046,6 +1048,7 @@ Job *DefaultActorImpl::claimNextJobOrGiveUp(bool actorIsOwned,
10461048
/*failure*/ std::memory_order_acquire))
10471049
continue;
10481050
LOG_STATE_TRANSITION;
1051+
_swift_tsan_acquire(this);
10491052

10501053
// If that succeeded, we can proceed to the main body.
10511054
oldState = newState;
@@ -1108,6 +1111,11 @@ Job *DefaultActorImpl::claimNextJobOrGiveUp(bool actorIsOwned,
11081111
continue;
11091112
}
11101113
LOG_STATE_TRANSITION;
1114+
1115+
if (jobToRun)
1116+
_swift_tsan_acquire(this);
1117+
else
1118+
_swift_tsan_release(this);
11111119

11121120
// We successfully updated the state.
11131121

@@ -1341,6 +1349,7 @@ bool DefaultActorImpl::tryAssumeThread(RunningJobInfo runner) {
13411349
/*success*/ std::memory_order_relaxed,
13421350
/*failure*/ std::memory_order_acquire)) {
13431351
LOG_STATE_TRANSITION;
1352+
_swift_tsan_acquire(this);
13441353
return true;
13451354
}
13461355
}

test/Sanitizers/tsan/actor_counters.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ actor Counter {
3232
value = value + 1
3333
return current
3434
}
35+
36+
deinit {
37+
for i in 0..<value {
38+
assert(scratchBuffer[i] == 1)
39+
}
40+
}
3541
}
3642

3743

0 commit comments

Comments
 (0)