How can I confirm that our code is thread safe?

Anyone can provide me a way that can prove my code
is tread safe? Or how can I test my code is not tread
safe?

Thanks
choudesAsked:
Who is Participating?
 
SpideyModCommented:
PAQ'd

SpideyMod
Community Support Moderator @Experts Exchange
0
 
Anthony2000Commented:
choudes,

Do you know exactly what thread safe is?
Then I will know where to start to help you.

Anthony.
0
 
weismatCommented:
Thread-safe is a term used to describe a routine that can be called from multiple programming threads without unwanted interaction between the threads. Thread safety is of particular importance to Java programmers, since Java is a programming language that provides built-in support for threads. By using thread-safe routines, the risk that one thread will interfere and modify data elements of another thread is eliminated by circumventing potential data race situations with coordinated access to shared data.
It is possible to ensure that a routine is thread-safe by:

1. Making sure that concurrent threads use synchronized algorithms that cooperate with each other.
2. Confining the address of a shared object to one thread whenever an unsynchronized algorithm is active.

From my experience issues with thread save problems usually occur when you use static objects, methods or properties and you have some left overs there.

There is no silver bullet to secure this, but you should have a look at the static things first.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
bearwareCommented:
If you just want it thread safe, but you routine will not take advantage of threads. (This is the most common case for routines that are or might be used in a multithread environment i.e. library code)

All data must be  automatic, or object type.
No statics no globals.
I.E. No data is shared between threads.

If you use statics to share data between threads you should learn more.

0
 
jerntatCommented:
I'm just curious, would it be unsafe if i create an object dynamically using 'new' in a thread process?
0
 
SpideyModCommented:
All,
I am unlocking this question in preparation for cleanup.  I will return in 7 days to finalize this question.  Please leave any recommendations for the final state of this question, I will take all recommendations into consideration.  Failing any feedback, I may decide in 7 days to delete or PAQ this question with no refund.  Thanks.

SpideyMod
Community Support Moderator @Experts Exchange
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.