我要问你,如果我选择的话,哪一个一致设施(CMutex, CSemaphore, CEvent)能够使C++/MFC成为多管齐下。
这是一个真正的时间,即机器设想的应用,现在需要同时执行,而且需要从以前单一阅读的状况中重新加以证明。
A single iteration of my workflow is the following. I have 2 producers A,B (MFC Workers) that need to fill two separate data structures (1 each). A third thread, a consumer (MFC Worker as well) is blocked, until both data become available from A and B. Then, producers A and B must block (each, upon their data completion), C must wake up, perform a calculation, unblock A and B to continue and become blocked again, waiting for the next segments.
- I must not use queues (Actor-like) - the blocking is a requirement :(
- I tried CEvent and it works. AutoResetEvents for A,B to unblock a CMultiLock call on C and then a ManualResetEvent->Set() from C, to unblock A and B waiting on the latter event. My concern is when to reset this event (in case e.g. A miss the whole Set and then Reset.)
- Do semaphores with plurality of 2 may stand for a better solution?
最好。