P
PokerMan
Hi
I have a server listening and when it receives an object deserilalises it.
Reads it, does whatever it needs, reserialises it and then broadcasts it to
clients (depending on what object was sent, found when it deseriliased it).
The problem is this:
1) Server receives object, deserialises
2) reads and serilaises again
3) go into broadcast loop to all clients. <-------but while doing this
receives a new object and deserialises it!
My comment in point 3 i believe is what is occurring. How can i protect such
a situation. This is what i believe is the solution but i would like someone
to either confirm or point me the right way if i am wrong.
i do this on the broadcast now:
lock(staticObject)
{
DoBroadCast(objToSend);
}
My thinking is that by doing that:
1) it locks any other thread from altering my objToSend object until
DoBroadcast is done with it.
2) All new objects sent to server will wait until they can access the obj so
they can deseriliase into it.
3) Broadcast finishes, releases lock, andnext object can now be deserialised
and used by server.
Am i right in my logic of how it will react to that lock?
Thanks
I have a server listening and when it receives an object deserilalises it.
Reads it, does whatever it needs, reserialises it and then broadcasts it to
clients (depending on what object was sent, found when it deseriliased it).
The problem is this:
1) Server receives object, deserialises
2) reads and serilaises again
3) go into broadcast loop to all clients. <-------but while doing this
receives a new object and deserialises it!
My comment in point 3 i believe is what is occurring. How can i protect such
a situation. This is what i believe is the solution but i would like someone
to either confirm or point me the right way if i am wrong.
i do this on the broadcast now:
lock(staticObject)
{
DoBroadCast(objToSend);
}
My thinking is that by doing that:
1) it locks any other thread from altering my objToSend object until
DoBroadcast is done with it.
2) All new objects sent to server will wait until they can access the obj so
they can deseriliase into it.
3) Broadcast finishes, releases lock, andnext object can now be deserialised
and used by server.
Am i right in my logic of how it will react to that lock?
Thanks