473,408 Members | 1,867 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,408 software developers and data experts.

Can static member cause a race condition?

Hi,

I have a quick question on the following scenario.

Given the below static member:

public Class Example1
{
public static Test(int x)
{
int y = x;
//Do some busy work.
return y;
}
}

and 2 seperate sessions/users calling the static member at the same
time

User1: Example1.Test(5); //Should return 5
User2: Example1.Test(10); //Should return 10

Can there ever be the possibility of User1 getting a value of 10 back
instead of 5. I know that the Test member is a class member and that
there is only one instance of it, but I am not sure about parameter x.
Can User2 overwrite parameter x for User1?

Aug 7 '06 #1
1 1427
Can there ever be the possibility of User1 getting a value of 10 back
instead of 5. I know that the Test member is a class member and that
there is only one instance of it, but I am not sure about parameter x.
Can User2 overwrite parameter x for User1?
No. If the method works with any static fields it could. But
locally-declared parameters and variables are safe.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Expect the unaccepted.

<al*********@gmail.comwrote in message
news:11**********************@n13g2000cwa.googlegr oups.com...
Hi,

I have a quick question on the following scenario.

Given the below static member:

public Class Example1
{
public static Test(int x)
{
int y = x;
//Do some busy work.
return y;
}
}

and 2 seperate sessions/users calling the static member at the same
time

User1: Example1.Test(5); //Should return 5
User2: Example1.Test(10); //Should return 10

Can there ever be the possibility of User1 getting a value of 10 back
instead of 5. I know that the Test member is a class member and that
there is only one instance of it, but I am not sure about parameter x.
Can User2 overwrite parameter x for User1?

Aug 7 '06 #2

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

Similar topics

5
by: GIMME | last post by:
One of my coworkers insists that one should never use static methods because race conditions exist. Thinking along the lines that all variable assignments are assignments to static variables. ...
3
by: Bernhard Kick | last post by:
Hi all, I saw this code in the book "Accelerated C++" (chapt 11, iirc): template <class T> class Vec { ... std::allocator<T> alloc; // object to handle memory allocation // ??would static...
8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
7
by: Sunny | last post by:
Hi all, According C# Language Specification : 10.11 Static constructors: The static constructor for a class executes at most once in a given application domain. The execution of a static...
10
by: McFly Racing | last post by:
Thread Locking In Static Methods I have the need for a Log Manger class that has static methods. Normally I would use the lock statement or a Monitor statement both of which take a...
5
by: WebMatrix | last post by:
Hello, It might seem like a stupid question to some. But I need to put this issue to rest once and for all, since it keeps coming up in code reviews every now and then. There’s a static...
1
by: philwozza | last post by:
Hi I have a THREAD class that uses the static variable NextThreadID to store the id of the next thread to be created and a static Mutex to protect it. class THREAD { public: int Start(void);...
2
by: antonyliu2002 | last post by:
I do not quite understand the race condition. As I posted a couple of days ago, I create a PDF on the fly in my web application at regular intervals. Users will be able to download the PDF...
7
by: Berryl Hesh | last post by:
I wouldn't nomally post this here, as it has something to do with the ListView control usage I think, or maybe with a race condition or some windoes messaging. I'm just not sure. The test below...
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.