.Net Thread Communication (.Net 2/3)

Share

One Comment

  1. volatile doesn’t make ThreadCount thread-safe, it just makes sure _threadCount isn’t cached to a registry.

    For example “ThreadCount++” compiles to IL similar to the following:
    callvirt instance int32 Namespace.MyClass::get_Count()
    ldc.i4.1
    add
    callvirt instance void Namespace.MyClass::set_Count(int32)

    clearly, _threadCount can change between get_Count and set_Count.

Leave a Reply