Skip to content

Commit ae9da64

Browse files
authored
Remove a volatile access from Task.Id (#43891)
1 parent 0bf8106 commit ae9da64

File tree

1 file changed

+2
-2
lines changed
  • src/libraries/System.Private.CoreLib/src/System/Threading/Tasks

1 file changed

+2
-2
lines changed

src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public class Task : IAsyncResult, IDisposable
120120

121121
internal static int s_taskIdCounter; // static counter used to generate unique task IDs
122122

123-
private volatile int m_taskId; // this task's unique ID. initialized only if it is ever requested
123+
private int m_taskId; // this task's unique ID. initialized only if it is ever requested
124124

125125
internal Delegate? m_action; // The body of the task. Might be Action<object>, Action<TState> or Action. Or possibly a Func.
126126
// If m_action is set to null it will indicate that we operate in the
@@ -1179,7 +1179,7 @@ public int Id
11791179
{
11801180
get
11811181
{
1182-
if (m_taskId == 0)
1182+
if (Volatile.Read(ref m_taskId) == 0)
11831183
{
11841184
int newId = NewId();
11851185
Interlocked.CompareExchange(ref m_taskId, newId, 0);

0 commit comments

Comments
 (0)