What does this mean?

  • Thread starter Thread starter John Pugh
  • Start date Start date
J

John Pugh

I'm learning VB.NET (I barely have a grip on classes,
inheritance and polymorphism though), and I was looking
at some of the terms on the MSDN site. What does it mean
if something is "thread safe" or not?

Thanks
 
Hi,

Threads are procedures run in the background. Thread safe means it
can safely be run in the background.

Ken
---------------
I'm learning VB.NET (I barely have a grip on classes,
inheritance and polymorphism though), and I was looking
at some of the terms on the MSDN site. What does it mean
if something is "thread safe" or not?

Thanks
 
If there are no issues when two threads access some code then its said to be
Thread Safe.
HTH
rawCoder
 
Lets say that you have two functions (methods) running simultaneously

Function A and Function B. Or we can call them: Thread A and Thread
B. Both these functions update and read from a variable C. What would
happened if both Thread A and B try to update the variable C at the
same time? if the variable is not thread safe, the data gets corrupted.
if it is thread safe however, it should be done smoothly.


Ahmed
 
You could make C threadsafe by using this code:

System.Threading.Interlocked.Increment(C)

if all you wanted to do was increment the variable C.
Otherwise, in VB you can do:

SyncLock Me
'do something with C
End SyncLock
 
I was just explaining the difference between thread safe and not thread
safe. but thanks for the info. :)
 
There is one other potential problem:

If function A is intermittently updating C, and function B is called in a
context that does not anticipate the activities of function A, then the
value of Function B will deviate from what was intended.

So it is important to remember that being thread-safe is no guarantee
against the usual problems associated with public/global variables and their
equivalents...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top