Which features make a class to be thread-safe?

Viewed 14079

In MSDN some .NET classes described like this:

"This type is thread safe."

or

"Public static (Shared in Visual Basic) members of this type are thread safe. Instance members are not guaranteed to be thread-safe.".

My question is which features make a class to be thread-safe?

  • Is there any standard, recommendation or guidelines for thread-safety programming?

  • When I use lock(C#) keyword, it means my class is thread-safe or not?

  • How to I evaluate thread-safety of a class? Is there any TESTS to be sure that a class is 100% thread safe?

Example:

public class MyClass
{
    public void Method()
    {
        lock (this)
        {
            // Now, is my class 100% thread-safe like Microsoft classes?
        }
    }
    type m_member1;
    type m_member2;
}

thanks

6 Answers
Related