Atomic writes in ConcurrentDictionary #65600
-
Source code of But the current revision of ECMA-335 standard says:
Value in s_isValueWriteAtomic = Unsafe.SizeOf<TValue>() <= IntPtr.Size; Currently, the type like I checked my assumption using SharpLab: public class C {
public struct S
{
public int X, Y;
}
public static void M(in S x1, out S x2) => x2 = x1;
public static void M2(in long x1, out long x2) => x2 = x1;
} Assembly code: ; Core CLR 6.0.121.56705 on amd64
C..ctor()
L0000: ret
C.M(S ByRef, S ByRef)
L0000: mov rax, [rcx]
L0003: mov [rdx], rax
L0006: ret
C.M2(Int64 ByRef, Int64 ByRef)
L0000: mov rax, [rcx]
L0003: mov [rdx], rax
L0006: ret As we can see here, read/write of word-sized value type are atomic. EDIT: Any type that is less than or equal to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That seems reasonable to me, if you want to throw up a PR maybe we will discover whether it's not 🙂 |
Beta Was this translation helpful? Give feedback.
That seems reasonable to me, if you want to throw up a PR maybe we will discover whether it's not 🙂