ACE_WFMO_Reactor 多线程跑的时候需要注意自己处理同步:
Unlike those using select()-based reactors, multithreaded applications can demultiplex and dispatch events concurrently using the ACE_WFMO_Reactor::handle_events() method. [2] In the multithreaded case it's therefore possible that different threads will dispatch events simultaneously to the same event handler.
Event handlers must therefore explicitly protect against race conditions when the handle_events() event loop is executed by multiple threads on the same ACE_WFMO_Reactor object. The ACE_TP_Reactor avoids these race conditions by implementing an internal protocol that automatically suspends a handle before dispatching its event handler. Any follower thread that subsequently becomes the leader doesn't dispatch events on the affected handle until the callback is complete and the handle is resumed.
引用楼主的话:
其次,你需要在handle_input(),和handle_timeout()以及handle_output(),和handle_timeout()中考虑同步,注意是handle_**put与handle_timeout()之间才有同步问题,而handle_input()和handle_output()之间不用考虑。
对比书上的解释:
Concurrency considerations. Multiple threads running an ACE_TP_Reactor event loop can process events concurrently on different handles. They can also dispatch timeout and I/O callback methods concurrently on the same event handler. The only serialization in the ACE_TP_Reactor occurs when I/O events occur concurrently on the same handle.
查了一下msdn你说的是正确的,handle_output再次触发的时候,一定处于可以发送的状态了。
The FD_WRITE network event is handled slightly differently. An FD_WRITE network event is recorded when a socket is first connected with connect/WSAConnect or accepted with accept/WSAAccept, and then after a send fails with WSAEWOULDBLOCK and buffer space becomes available. Therefore, an application can assume that sends are possible starting from the first FD_WRITE network event setting and lasting until a send returns WSAEWOULDBLOCK. After such a failure, the application will find out that sends are again possible when an FD_WRITE network event is recorded and the associated event object is set.
仔细看了一下,你提出的这个例子的问题
如果TP_Reactor真的无法保证the reactor ensures that only one of the handle_*()
methods of an event handler is called at a time,
那么用起来还真是不保准。
用之前至少要需要自己跑一下这个例子,看看实际效果了。
原帖由 modern 于 2009-6-29 15:02 发表
仔细看了一下,你提出的这个例子的问题
如果TP_Reactor真的无法保证the reactor ensures that only one of the handle_*()
methods of an event handler is called at a time,
那么用起来还真是不保准。
用之前至少要 ...