if i want to send a client multiple id’s in a multi-threaded program how would i do so such that the correct id is recieved, for example, in a normal integrated application i would just do int id = service.createSession(); in which service is a local instance of the server running in the same process as my application
eg where Service service = new Service();
how would i achieve the same with an actual IPC based server
as my current approach is to store the id in a global variable and then access it
eg
sendMessageToServer(TerminalService.MSG_CREATE_SHELL_SESSION, TerminalService.toInt(true));
// SERVER:
// case MSG_CREATE_SHELL_SESSION:
// sendMessageToAllClients(
// MSG_SESSION_CREATED,
// createShellSession(toBoolean(msg.arg1)
// );
// CLIENT:
// case TerminalService.MSG_SESSION_CREATED: SESSION_ID = msg.arg1;
int session_id = SESSION_ID;
however i do not think this would work in a multi-threaded context as if, say T1 creates a session, and T2 creates a session, both will data race to create the session first and then data race to store the produced session id
eg T1 may get T2's session id and vice versa