Solved

How can I confirm that our code is thread safe?

Posted on 2001-09-03
6
161 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

786 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