Suppose that there're two types of packet in the chatting server. Those two packets are used for getting the status of another user. One(call this as REQ-STAT, RES-STAT) is request-and-response form and another one(NOT-STAT) is notification form packet.
For instance, if I send [REQ-STAT simpson] to the server and I may get [RES-STAT simpson online]. Or, if the user SIMPSON's status has been changed, I'll get the user's status like [NOT-STAT simpson offline].
Okay, the server is running on multi-core machine and using multiple threads, of course.
If the server get [REQ-STAT simpson] packet, the server will prepare packet [RES-STAT simpson online] - if the SIMPSON is online. At this point, the SIMPSON logged out, so the server send packet [NOT-STAT simpson offline] to the client. After the server sent [NOT-STAT simpson offline] packet, [RES-STAT simpson online] packet is sent
// the server lock during using user data structure but not for the whole process.
------[REQ-STAT simpson]------> simpson is online and prepare response packet
<--[NOT-STAT simpson offline]-- simpson has been logged out and send not packet
<--[RES-STAT simpson online]--- send response
// the latest packet does not have the latest information !!!
Can above scenario be happen if LOCK does not used for whole process? If so, do I should lock that all? Any other solutions?
Thanks.