473,396 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

A thread safety question

Hi all.

I have a page and a control that both raise the same issue:

I have the following code:

private bool isInCreateMode = false;

public bool IsInCreateMode{
get{
...
}
set{
...
}
}

My question is, given that this variable is global ie, outside the context
of a given method call, is it thread safe?

I know that in java, declaring a variable globaly like that can cause
problems.

Do I need to worry?

Thanks

Simon
Nov 18 '05 #1
3 851
Hi Simon,

If the control sits on a Web Page it's probably safe, unless you have
static/shared members in the control.

Remember that a control is an object that gets instantiated by the HTTP
Runtime on a particular thread. One thread / one Page typically (unless you
run async requests or fire your own threads). Another thread can't easily
call into this page and any control on the page by default is private
anyway, so unless you're doing somehting tricky with state (sessions,
Application object, or caching your data in a static member somewhere) in
your application you won't have any problems.

You do need to watch out for static/shared members in components or
controls. Those can easily cause problems if not properly managed...

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
----------------------------------
Making waves on the Web
"Simon Harvey" <sh856531@microsofts_free_email_service.com> wrote in message
news:Oy**************@TK2MSFTNGP12.phx.gbl...
Hi all.

I have a page and a control that both raise the same issue:

I have the following code:

private bool isInCreateMode = false;

public bool IsInCreateMode{
get{
...
}
set{
...
}
}

My question is, given that this variable is global ie, outside the context
of a given method call, is it thread safe?

I know that in java, declaring a variable globaly like that can cause
problems.

Do I need to worry?

Thanks

Simon

Nov 18 '05 #2
Hi there Rick,

Thanks for your reply. I just want to check one thing. You talked about
controls on a page there which was very helpful.

I also declare global variables and properties on pages themselves. I'm
guessing that that will be fine as well given that you said one page/one
thread

I just wanted to make sure before i go and arse my companies website
entirely!

:-)

Simon
Nov 18 '05 #3
global variables are not thread safe. You need to protect them. It works the
same in c# as in java or most other languages for that matter.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"Simon Harvey" <sh856531@microsofts_free_email_service.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi there Rick,

Thanks for your reply. I just want to check one thing. You talked about
controls on a page there which was very helpful.

I also declare global variables and properties on pages themselves. I'm
guessing that that will be fine as well given that you said one page/one
thread

I just wanted to make sure before i go and arse my companies website
entirely!

:-)

Simon

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: rnn98 | last post by:
hi, my multithread application, running under solaris box, is crashing eventually. I tried to spot and substitute functions not "thread safe", but I guess my search wasn't good enough. I have put...
4
by: Jonathan Burd | last post by:
Greetings everyone, Here is a random string generator I wrote for an application and I'm wondering about the thread-safety of this function. I was told using static and global variables cause...
9
by: Alexander Fleck | last post by:
Hi, I' ve to make a software module thread safe. I know how to realize that and what' re the main topics of thread safety. But I don' t know how thread safety can be tested. I read about a test...
17
by: Rainer Queck | last post by:
Hi NG, one more question about thread safety of generic lists. Let's assume a generic list: List<MyTyp> aList = new List<MyType>(); Would it be a problem if one thread removes elements from...
5
by: jzlondon | last post by:
Hi, I have a question that I wonder if someone might be able to help me with... I have an application which handles real-time financial data from a third party source. The data comes in via...
6
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it...
13
by: arun.darra | last post by:
Are the following thread safe: 1. Assuming Object is any simple object Object* fn() { Object *p = new Object(); return p; } 2. is return by value thread safe?
6
by: Olumide | last post by:
Hi - I've got a class that contains static member functions alone, all of whose arguments are passed by reference as shown below: class MySpiffyClass{ // no constructor, destructor or...
13
by: Henri.Chinasque | last post by:
Hi all, I am wondering about thread safety and member variables. If I have such a class: class foo { private float m_floater = 0.0; public void bar(){ m_floater = true; }
2
by: k3xji | last post by:
Hi all, This will probably be a long question/short answer, sorry, but I have wandered net about the subject and really feel cannot find just enough information.I want to ask my question by...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.