A thread safe is an unfortunate term because it does not
have a solid definition.
Thread safe basically means a bit of code or a piece of
code will function correctly even when accessed by multiple threads. Multiple
problems can occur if you use non-thread safe code in threaded application. The
most common problem is deadlocking.
Example:-
public class WidgetManipulator
{
public
int TotalWidgets = 0;
public
void AddWidget()
{
TotalWidgets++;
Console.WriteLine("Total
widgets = " + TotalWidgets.ToString());
}
public
void RemoveWidgets()
{
TotalWidgets
-= 10;
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.