English 中文(简体)
我应选择什么同步办法避免在实时应用C++/MFC时出现僵局?
原标题:What synchronization scheme should I choose to avoid deadlock on a realtime, C++/MFC application?

我要问你,如果我选择的话,哪一个一致设施(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.

  1. I must not use queues (Actor-like) - the blocking is a requirement :(
  2. 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.)
  3. Do semaphores with plurality of 2 may stand for a better solution?

最好。

最佳回答

C必须等两件事情才能发生,因此最符合逻辑的是,它要等两件自动打造的物体:一个是A设定的,另一个是B。

When C is done, A and B must each then wait for a notification. Since there are two threads, and both must wake up, the natural thing is to use another pair of auto-reset CEvent objects, one for each of A and B. C can then set both when it is done.

一张2张 count光的ema光灯将用来唤醒C-C,两度等待,而A和B每一方都通知——但这意味着C在第一次通知之后必须警醒,以等待第二次,这并不理想。

之后,用2个 count子来检测A和B,就有可能发生偷窃的催泪和混乱。 C 信号是ema的两倍。 催复和发出信号,处理和通知C,然后再等待ema。 自2006年以来 Bn t 尚未消亡,仍然有烟雾,因此A再次照亮。 同时 B并不 st,因为它获得了另一个信号,C被 st,因为它将等待B的下一个价值。

另一种选择是使用Windows vant Variable AP,而不是使用事件,但在这方面似乎只有MFC包裹。 见

问题回答

我将略微修改你的备选办法2——利用CMultiLock进行两次活动,以阻止C;然后使用另一场<>pair<>>>>事件,以阻止A和B.C。 然后,你不再有争.。

我建议采用一种信号处理系统,使用一种受相互保护的反射系统。 这使得所有同步工作都局限于一个不另.的小类别。

A starts
A writes A-Data
A signals
A stops

B starts
B writes B-Data
B signals 
B stops

C starts
C reads A-Data and B-Data
C starts A, B
C stops


*Signal Class*

Mutex protected counter attribute

Receives signal for A, increment counter
Receives signal for B, increment counter
IF counter equals 2,  clear counter and start C




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签