c++ - Synchronize asynchronous calls from more than one object -
i have 10 objects. each object different class. requests sent objects (method calls returning values) comes different threads.
i need synchronise method calls, 1 must executed @ time. requests have higher priority others. means if there more requests waiting executed , 1 sent - higher priority other waiting execution, shall executed next one.
i don't know how solve problem in c++. thinking command pattern require lot of "manual" coding. have convert each method call command object. , problem return value. have idea, pattern can used here?
for synchronization, may use form of mutual exclusion 1 thread @ time manipulating object.
dealing priorities, want priority queue comparator determining criteria type of request has greater priority.
each object accept request action , have priority associated it, , action (like suggested command pattern). using locking mechanism, update priority queue adding record, release it. must lock queue because accessed via multiple threads. no explicit sorting necessary -- queue in order of highest priority. therefore process command, first item in queue, if 1 available, , execute action.
Comments
Post a Comment