What does a "Thread Safety" class mean?

5

According to MSDN a WebApp Class (Microsoft.Owin.Hosting) is Thread Safety . What does this mean exactly?

This class specifically has a method Start that:

  

Start a web app ....

Would every request to this app be handled by a Thread ?

    
asked by anonymous 26.07.2015 / 22:18

2 answers

4

The article does not say that the class is " thread safety ", this is a title of the section that says:

Any static pubic member of this class is " thread safe ", that is, it can be manipulated by multiple tasks simultaneously.

There is also information that any instance of the class (objects created from this class) have no guarantee of being thread safe . Instances of the class should not be used by multiple tasks simultaneously.

In this specific case, it means that multiple tasks can use implementations of the Start method simultaneously, each method call does not cause problems in other calls.

    
26.07.2015 / 22:30
2

It means that static members of this class can operate seamlessly across multiple threads. They do not have anything that can cause problems when running concurrently or if they have a situation that might cause problems, they already have a mechanism that leaves no problem occurring. So you can access these members concurrently without fear.

But instance members are not guaranteed as thread safe . What does not matter in this case, since the class is static.

If it were an instantiable class, you could still use the instances concurrently by providing mechanisms that ensure concurrent operation. Or you can still use it in parallel but not competing.

Of course, programming using threads is not something simple, you still need to know what you're doing even though everything in the class is thread safe .

Static classes are not used more than once in the application. Although nothing prevents it from being done, this does not seem to be the case, it seems to be something that should be unique in the application. Therefore, in general, it is not used with threads . At least it is my understanding by reading the little documentation. See the example .

    
26.07.2015 / 22:36