Solved

How can I confirm that our code is thread safe?

Posted on 2001-09-03
6
166 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:choudes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 8

Expert Comment

by:Anthony2000
ID: 6470408
choudes,

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

Anthony.
0
 

Expert Comment

by:weismat
ID: 6474030
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
 
LVL 1

Expert Comment

by:bearware
ID: 6526608
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:jerntat
ID: 6626929
I'm just curious, would it be unsafe if i create an object dynamically using 'new' in a thread process?
0
 

Expert Comment

by:SpideyMod
ID: 8275949
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
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8330185
PAQ'd

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question