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

Concurrency and static function and web application

Hi,
It just come to my mine about conncurreny and static functions. This
would not be a problem in window application because each thread has
it own stack (and heap? forgot...).

I'm using some static function in a web application. If the function
take a bit of time to complete and when two sessions call the same
function, what would happen?
For example:

class cfoo
{
static int i = 0;

public static void foo()
{
i++;
...
// do something with i
}
}

When two sessions call foo() at the same time, and both processed i++
but not // do something with i, then the value is not correct (unless
that's what intended)

I understand the above example, but how about the following?

class cfoo
{
public static void foo(int i)
{
// do something
.....
// do something with i
}
}

in this case, when two sessions call foo(int i) at the same time but
with different values, what would happen? Will the function work as
normal? Or it will behave unpredictable?
Thank for concern,
Homa Wong
Nov 18 '05 #1
1 1559
> It just come to my mine about conncurreny and static functions. This
would not be a problem in window application because each thread has
it own stack (and heap? forgot...).
absolutely false. they suffer the same malaise.

It will have unpredictable results. Classic race condition. When using
anytype of global variable, you must take care to synchronize access. But I
think you already knew that.

Regards
--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"Homa" <ho******@yahoo.com> wrote in message
news:a9**************************@posting.google.c om... Hi,
It just come to my mine about conncurreny and static functions. This
would not be a problem in window application because each thread has
it own stack (and heap? forgot...).

I'm using some static function in a web application. If the function
take a bit of time to complete and when two sessions call the same
function, what would happen?
For example:

class cfoo
{
static int i = 0;

public static void foo()
{
i++;
...
// do something with i
}
}

When two sessions call foo() at the same time, and both processed i++
but not // do something with i, then the value is not correct (unless
that's what intended)

I understand the above example, but how about the following?

class cfoo
{
public static void foo(int i)
{
// do something
.....
// do something with i
}
}

in this case, when two sessions call foo(int i) at the same time but
with different values, what would happen? Will the function work as
normal? Or it will behave unpredictable?
Thank for concern,
Homa Wong

Nov 18 '05 #2

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

Similar topics

4
by: Robert Schuldenfrei | last post by:
Dear NG, I was about to "improve" concurrency checking with a Timestamp when I discovered that my current code is not working. After about a day of beating my head against the wall, I am...
7
by: Homa | last post by:
Hi, I'm thinking what will happen if two users access a page at the same time. If there are any local variable in the page, will this cause concurrency problem? Simarily, if this page need to...
4
by: Jason Chu | last post by:
I have a big asp.net app that does many functions, some do alot of database cross searching, some that does upload/download from database. When two users use the application, sometimes, if one of...
3
by: Dave | last post by:
Are there any issues with concurrency on static methods creating instances such as in the data access code below? Or if I wanted to expand it to use an ADO.NET transaction and having two users...
2
by: thomas | last post by:
Hi, I'm writting an extension in c for php. Looking at the life cycle of the extensions it looks like each extension is started up within its own thread - is this correct? When each request...
9
by: Anthony Paul | last post by:
Hello everyone! I've been reading a great book on SOA called "Enterprise SOA" and found that it answered many questions. However, there's one particular scenario (involving business-rules)...
6
by: =?Utf-8?B?QmlsbGlhbQ==?= | last post by:
I am not sure if this is the right group to post to but I fugured I'd start here. Let me know if there is a more appropriate group. I wanted to try the forums before I wait 3+ hours on the phone to...
8
by: Roger.Noreply | last post by:
Hi, Sql-Server 2000, 2005. A report fetches a lot of rows using the "WITH (ROWLOCK)" syntax (the sql is generated on the fly by a tool and not easily changeable). SELECT col1, col2 FROM mytab...
5
by: John | last post by:
Hi I have developed the following logic to handle db concurrency violations. I just wonder if someone can tell me if it is correct or if I need a different approach.Would love to know how pros...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.