Solved

How can I confirm that our code is thread safe?

Posted on 2001-09-03
6
164 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
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Debian 3.16.7 3 152
predeployment and postdeployment script in linux rpm 1 36
„dd“ vs „ddrescue“ 28 248
Getting permission denied on linux running a script 3 70
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 demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 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