views:

178

answers:

2

Hi, I'm making a cross plateform program that embbed a small RARP server (implemented with winpcap/pcap) and runs 2 TCP IP servers. I have to use C++.

So i will have at least 4 threads, the main one wich countain the controller, 2 TCP/IP async socket, and the RARP server.

I planned to use c++ BOOST Asio and Thread, because i need to run this program in both linux and windows XP. (and i can't use Qt)

I would perform asynchronous Inter thread communication.

For exemple fire events inside a loop without blocking the loop

How can i do that? With a portable librairy preferably.

Thank you

+1  A: 

There's no generic solution to this, you can't just interrupt a thread and deliver a notification to be processed. That causes horrible re-entrancy problems and large servings of deadlock. A notification can only be processed when the thread is in a quiescent state.

An operating system usually has services available that make it possible. In Windows this is typically done by posting a message to the message queue. Read by the message loop, which is the 'idle' state for a UI thread. Or by leveraging asynchronous procedure calls, fired when the thread is blocking and explicitly allowed APCs to run.

But you cut this off by requiring a non-platform specific solution. In which case you're pretty much doomed to re-invent an OS feature. You'll need a thread-safe queue that you poll in the thread that needs to receive the notification. A message queue, read by a message loop.

Hans Passant
Because i already use boost asio, im using boost asio io_service object to make async function calls. thank you.
MiniScalope
+1  A: 

Take a look at ICE messaging

It supports syncrhonous and asyncrounous messaging between processes whether they are on the same node or not.

There are bindings for C++, Obj-C, Java, C#, Python, Ruby, and PHP.

Travis