Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tag that a class is thread-safe (or not)?

Tags:

In MSDN documentation we see :

Console

Thread Safety

This type is thread safe.

TextWriter

Thread Safety

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

I've developed a similar (static) class to the Console one, so how can I tag it to thread safe? I'm extracting XML documentation and I would know how I can this part like in the MSDN Doc'.

Hope I'm clear enough...

Thanks for help !

like image 758
Arnaud F. Avatar asked Dec 27 '10 16:12

Arnaud F.


People also ask

How do I know if a code is thread-safe?

To test if the combination of two methods, a and b, is thread-safe, call them from two different threads. Put the complete test in a while loop iterating over all thread interleavings with the help from the class AllInterleavings from vmlens. Test if the result is either an after b or b after a.

How do you make a class thread-safe?

To make these classes thread-safe, you must prevent concurrent access to the internal state of an instance by more than one thread. Because Java was designed with threads in mind, the language provides the synchronized modifier, which does just that.

How do you make a method thread-safe in Java?

Using Atomic Variable Using an atomic variable is another way to achieve thread-safety in java. When variables are shared by multiple threads, the atomic variable ensures that threads don't crash into each other.


2 Answers

The Sandcastle Help File Builder project contains a useful XML Comments Guide.

It documents the threadsafety tag:

<threadsafety static="true|false" instance="true|false"/> 

The root SHFB documentation page is here.

like image 181
Olly Avatar answered Oct 29 '22 01:10

Olly


Add this detail to the <summary> or <remarks> tags.

There is no specific tag or convention on how to indicate a class is thread safe - you need to write it in your documentation.

like image 43
Oded Avatar answered Oct 29 '22 02:10

Oded