Avoid stuck calling callback

Posted by andlomba on Stack Overflow See other posts from Stack Overflow or by andlomba
Published on 2010-03-08T11:54:37Z Indexed on 2010/03/12 10:27 UTC
Read the original article Hit count: 204

Filed under:
|
|

Hello all,

This is a question about generic c++ event driven applications design.
Lets assume that we have two threads, a "Dispatcher" (or "Engine"...) and a "Listener" (or "Client"...).
Let's assume that I write the Dispatcher code, and release it as a library. I also write the Listener interface, of course.
When the Dispatcher executes (after Listener registration)

listenerInstance.onSomeEvent();

the event handling code will actually be executed by the Dispatcher thread, so if the person that implements the Listener writes something like

void Listener::onSomeEvent() { while(true) ; }

The Dispatcher will stuck forever.

Is there a "plain old c++" (I mean no boost or libsigc++) way to "decouple" the two classes, so I can be sure that my Dispatcher will work fine whatever the Listeners does in the callbacks?

bye and thanks in advance,
Andrea

© Stack Overflow or respective owner

Related posts about c++

Related posts about callback