Skip to content

Commit 38a2acf

Browse files
committed
Fixed race condition
1 parent e5fe8be commit 38a2acf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/DotNext.Threading/Threading/LinkedCancellationTokenSource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ private protected set
101101
/// </summary>
102102
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
103103
internal bool IsRootCause => CanInlineToken
104-
? ReferenceEquals(this, Volatile.Read(in cancellationOrigin.Item1))
105-
: CancellationOrigin == Token;
104+
? Volatile.Read(in cancellationOrigin.Item1) is not { } tokenCopy || ReferenceEquals(this, tokenCopy)
105+
: Token == CancellationOrigin;
106106

107107
// This property checks whether the reinterpret cast CancellationToken => CancellationTokenSource
108108
// is safe. If not, just box the token.

0 commit comments

Comments
 (0)