Skip to content

Commit e5fe8be

Browse files
committed
Fixed regression
1 parent bcad197 commit e5fe8be

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/DotNext.Threading/Threading/LinkedCancellationTokenSource.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,21 @@ public CancellationToken CancellationOrigin
8888
: Unsafe.Unbox<CancellationToken>(tokenCopy.Item1)
8989
: Token;
9090

91-
private protected set => cancellationOrigin = InlineToken(value);
91+
private protected set
92+
{
93+
var tokenCopy = InlineToken(value);
94+
Volatile.Write(ref cancellationOrigin.Item1, tokenCopy.Item1);
95+
}
9296
}
9397

9498
/// <summary>
9599
/// Gets a value indicating that this token source is cancelled by the timeout associated with this source,
96100
/// or by calling <see cref="CancellationTokenSource.Cancel()"/> manually.
97101
/// </summary>
98102
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
99-
internal bool IsRootCause => CanInlineToken ? ReferenceEquals(this, cancellationOrigin.Item1) : CancellationOrigin == Token;
103+
internal bool IsRootCause => CanInlineToken
104+
? ReferenceEquals(this, Volatile.Read(in cancellationOrigin.Item1))
105+
: CancellationOrigin == Token;
100106

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

0 commit comments

Comments
 (0)