Skip to content

Proposal: Hide Thread.VolatileRead and Thread.VolatileWrite #27997

@carlreinke

Description

@carlreinke

Rationale

Thread.VolatileRead and Thread.VolatileWrite delegate to Volatile.Read and Volatile.Write, but it is an incomplete delegation in that Volatile has support for bool whereas Thread does not.

I always reach for Thread.VolatileRead before Volatile.Read. Hiding it would help break this habit.

Proposal

 namespace System.Threading
 {
     public sealed class Thread : CriticalFinalizerObject
     {
         ...
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static byte VolatileRead(ref byte address) => Volatile.Read(ref address);
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static double VolatileRead(ref double address) => Volatile.Read(ref address);
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static short VolatileRead(ref short address) => Volatile.Read(ref address);
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static int VolatileRead(ref int address) => Volatile.Read(ref address);
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static long VolatileRead(ref long address) => Volatile.Read(ref address);
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static IntPtr VolatileRead(ref IntPtr address) => Volatile.Read(ref address);
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static object VolatileRead(ref object address) => Volatile.Read(ref address);
         [CLSCompliant(false)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static sbyte VolatileRead(ref sbyte address) => Volatile.Read(ref address);
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static float VolatileRead(ref float address) => Volatile.Read(ref address);
         [CLSCompliant(false)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static ushort VolatileRead(ref ushort address) => Volatile.Read(ref address);
         [CLSCompliant(false)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static uint VolatileRead(ref uint address) => Volatile.Read(ref address);
         [CLSCompliant(false)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static ulong VolatileRead(ref ulong address) => Volatile.Read(ref address);
         [CLSCompliant(false)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static UIntPtr VolatileRead(ref UIntPtr address) => Volatile.Read(ref address);
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static void VolatileWrite(ref byte address, byte value) => Volatile.Write(ref address, value);
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static void VolatileWrite(ref double address, double value) => Volatile.Write(ref address, value);
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static void VolatileWrite(ref short address, short value) => Volatile.Write(ref address, value);
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static void VolatileWrite(ref int address, int value) => Volatile.Write(ref address, value);
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static void VolatileWrite(ref long address, long value) => Volatile.Write(ref address, value);
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static void VolatileWrite(ref IntPtr address, IntPtr value) => Volatile.Write(ref address, value);
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static void VolatileWrite(ref object address, object value) => Volatile.Write(ref address, value);
         [CLSCompliant(false)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static void VolatileWrite(ref sbyte address, sbyte value) => Volatile.Write(ref address, value);
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static void VolatileWrite(ref float address, float value) => Volatile.Write(ref address, value);
         [CLSCompliant(false)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static void VolatileWrite(ref ushort address, ushort value) => Volatile.Write(ref address, value);
         [CLSCompliant(false)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static void VolatileWrite(ref uint address, uint value) => Volatile.Write(ref address, value);
         [CLSCompliant(false)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static void VolatileWrite(ref ulong address, ulong value) => Volatile.Write(ref address, value);
         [CLSCompliant(false)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
         public static void VolatileWrite(ref UIntPtr address, UIntPtr value) => Volatile.Write(ref address, value);
         ...
     }
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedarea-System.Threadingcode-analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixerhelp wanted[up-for-grabs] Good issue for external contributors

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions