mutex - Mutual Exclusion case -


hi have following question:

i have multi-threaded server can receive multiple requests @ same time. server manages session list. when request received, thread handling request has identify if session open (in session list) demanding client, or open new 1 in case client hasn't session open yet. far good. protect session list mutex when request comes in, list locked, browsed till according connection found , unlocked , pointer session returned (in order).

now question: considering multiple requests can received same client (and of them have treated), best practice protect sessions (knowing operations possible on sessions modify session info session can deleted request)?

example: 2 incoming requests. first request locks list, finds session, unlocks list , gets session. second request same after list has been unlocked. both have handle same session.

problem: if 1 of request meant close session? other request have handle session not aware has been closed (and deleted).

what solution propose?

thak in advance help.

your problem typical use case of observer pattern.

observer requests/clients. subject session. when event modify session, request/clients based on session notifyied occured on session.

so, session object has list of request/client. when modifies state of session, elements of list notifyied, synchronously. when notifying, can embedded more or less information depending of needs.

the typical trap of approach notification cycle. session notifies request modify session, etc.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -