Main loop is a recipient for two kinds of messages. First type message is frequent and work for this message is done in main loop thread. Second type message is rare, and upon its arrival parallel thread is awoken to do work for second type message. Work for second type message can take a lot of time and there is a possibility, that new message (or multiple messages) of second type arrives during this time. Occurance of second type message should be noted and after previous threaded work is done, new work should start, but only once no matter how many second type messages was received.
main thd work thd
|
2nd message-> |-->do work-------
| |
| |
2nd message-> | |
| |
2nd message-> | |
|<-- end ---------
|-->do work-------
| |
| |
| |
| |
| |
|<-- end ---------
|
|
For now i was thinking of using condition variable for waking of second type message thread, and a flag for reporting arrival of new second type messages.
Is there some proper design patern for such problem?
regards
Aucun commentaire:
Enregistrer un commentaire