Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I confirm that our code is thread safe?

Posted on 2001-09-03
6
Medium Priority
?
170 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
Technology Partners: 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

972 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