-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Threading
Milestone
Description
Background and motivation
.Net 9 now allows us to exchange more types like byte, short and enums. It would be nice to expand Volatile.Write() and Volatile.Read() with such overloads as well.
API Proposal
public static class Volatile
{
// Remove constraints from existing methods, making them work for primitives and throw for unsupported types,
// as was done with Interlocked.{Compare}Exchange
public static T Read<T>([NotNullIfNotNull(nameof(location))] ref readonly T location)
- where T : class?
public static void Write<T>([NotNullIfNotNull(nameof(value))] ref T location, T value)
- where T : class?
}API Usage
var x = SomeEnumType.DefaultValue;
Volatile.Write(ref x, SomeEnumType.NonDefaultValue);Alternative Designs
No response
Risks
No risks, everything already implemented in net9.0.
timcassell and NinoFloris
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Threading