March 23, 2004

Thread Safety - 2

This is a follow-up to my last weblog entry about thread safety.

Rethinking what I had written, I started to think "Of course that code is thread-safe. There is no static data." Now I see that in the .NET Framework Class Library reference manual, there are statements like this:

Thread Safety

Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.

So, does this mean that in the .NET terminology, an instance method is thread-safe if it is synchronized? That doesn't make any sense. It seems Microsoft's writers are being very sloppy in their use of terminology. If I were to take the statement too literally, I would use a global lock before I call any such instance method. After all, "not guaranteed to be thread safe" could mean that there is some data shared globally by every class, and that that shared data is changed by the instance method.

Posted by Doug Sauder at March 23, 2004 07:36 AM