SYSLIB0054: Thread.VolatileRead and Thread.VolatileWrite are obsolete

All overloads of the Thread.VolatileRead and Thread.VolatileWrite methods are obsolete, starting in .NET 9. Calling them in code generates warning SYSLIB0054 at compile time.

Reason for obsoletion

The .NET Framework implementation of the 64-bit overloads of the Thread.VolatileRead and Thread.VolatileWrite methods had incorrect atomicity. In .NET (Core), the implementation was changed to delegate to the Volatile.Read and Volatile.Write, respectively, which provide proper acquire/release semantics. In addition, the methods in the Thread class don't include an overload that accepts a Boolean argument, whereas the Volatile methods do. The methods were obsoleted to encourage use of the Volatile methods.

Workaround

Call Volatile.Read or Volatile.Write instead.

Suppress a warning

If you must use the obsolete APIs, you can suppress the warning in code or in your project file.

To suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the warning.

// Disable the warning.
#pragma warning disable SYSLIB0054

// Code that uses obsolete API.
// ...

// Re-enable the warning.
#pragma warning restore SYSLIB0054

To suppress all the SYSLIB0054 warnings in your project, add a <NoWarn> property to your project file.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
   ...
   <NoWarn>$(NoWarn);SYSLIB0054</NoWarn>
  </PropertyGroup>
</Project>

For more information, see Suppress warnings.