Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Concurrency and static function and web application

Reply
Thread Tools

Concurrency and static function and web application

 
 
Homa
Guest
Posts: n/a
 
      11-21-2003
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
 
Reply With Quote
 
 
 
 
Alvin Bruney
Guest
Posts: n/a
 
      11-21-2003
> 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Http Handler Factory and Possible Concurrency Issues on Application Start Jordan S. ASP .Net 6 06-02-2008 05:11 PM
How to call a non static function from a static function bhattacharjeesoft@gmail.com C++ 2 08-06-2007 11:03 AM
Re: Calling web service from web page; concurrency problems? Billy Jiggs ASP .Net 0 04-01-2004 02:27 PM
Re: Calling web service from web page; concurrency problems? Sami Vaaraniemi ASP .Net 0 04-01-2004 11:46 AM
concurrency and web-services Uli Java 1 07-04-2003 07:52 AM



Advertisments