3

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

MiniScalope
  • 1,429
  • 1
  • 16
  • 22
  • 4
    I think you'll have better luck getting an answer if you ask a more narrow version of this question. You have several questions in here, some not related to others.... It's very scattered. – SoapBox Aug 15 '10 at 10:46

2 Answers2

3

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
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Because i already use boost asio, im using boost asio io_service object to make async function calls. thank you. – MiniScalope Aug 20 '10 at 12:23
2

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.

Ternary
  • 2,401
  • 3
  • 31
  • 54