D
David
With a non-server app there is one instance of the program running and one
user 'using' it at a time. With this scenario I'm pretty comfortable with
variable scope and lifetime. With a server app there is one instance of the
program running but several simultaneous clients connecting to and 'using'
it. When I think about this I'm wondering what this may add to what needs to
be considered for scope and lifetime... is a scenario created where one
client will mess up another client if not handled right? I'm not referring
to thread synchronization. I'm comfortable with knowing when to lock, for
the most part. See very short partial code example and the 2 statements
following it and you will see what I'm talking about (as well as my lack of
experience )
class Server
{
//class globals
string g_s;
int g_i;
void methodA()
{
//member vars
int i;
string s;
}
int main(string[] args)
{
//code
}
}
assumption 1: every client would actually be accessing the same g_s and g_i
variables... eg. client1 sets g_i to 5, then client2 sets it to 2, then when
client1 reads it again it will be 2, not 5. (true/false)?
assumption 2: every client would be using their own distinct instances of i
and s when methodA() runs.... eg. client1 sets i to 5, client2 also running
sets i to 2, then when client1 reads it again it will still be 5.
(true/false)?
and finally: how would above two assumptions change, if at all, if methodA()
were declared static? or the variables were declared static?
user 'using' it at a time. With this scenario I'm pretty comfortable with
variable scope and lifetime. With a server app there is one instance of the
program running but several simultaneous clients connecting to and 'using'
it. When I think about this I'm wondering what this may add to what needs to
be considered for scope and lifetime... is a scenario created where one
client will mess up another client if not handled right? I'm not referring
to thread synchronization. I'm comfortable with knowing when to lock, for
the most part. See very short partial code example and the 2 statements
following it and you will see what I'm talking about (as well as my lack of
experience )
class Server
{
//class globals
string g_s;
int g_i;
void methodA()
{
//member vars
int i;
string s;
}
int main(string[] args)
{
//code
}
}
assumption 1: every client would actually be accessing the same g_s and g_i
variables... eg. client1 sets g_i to 5, then client2 sets it to 2, then when
client1 reads it again it will be 2, not 5. (true/false)?
assumption 2: every client would be using their own distinct instances of i
and s when methodA() runs.... eg. client1 sets i to 5, client2 also running
sets i to 2, then when client1 reads it again it will still be 5.
(true/false)?
and finally: how would above two assumptions change, if at all, if methodA()
were declared static? or the variables were declared static?