testing static member - thread safe?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?YmJn?=

    #1

    testing static member - thread safe?

    If many thread needs to test if one field of static class is null,

    if (StaticClass.fi eldA == null)

    will it be thread safe and doesn't need thread synchronization ?

    Bob
  • Jon Skeet [C# MVP]

    #2
    Re: testing static member - thread safe?

    On Sep 26, 9:06 am, bbg <b...@discussio ns.microsoft.co mwrote:
    If many thread needs to test if one field of static class is null,
    >
    if (StaticClass.fi eldA == null)
    >
    will it be thread safe and doesn't need thread synchronization ?
    Only if fieldA is either readonly (and initialized as part of the
    class initialization for StaticClass) or volatile.

    Otherwise you could end up seeing "stale" values.

    Jon

    Comment

    Working...