   boost:asio thread callback
  Hello,I am running a boost::asio udp server on a different thread by enclosing the launch code in a function:void sockets() {try {boost::asio::io_service io_service;udp_server server(io_service);io_service.run();}catch (std::exception& e){//handle error}}and then in my main() doing:boost::thread MyThread(sockets);(not sure if this is the correct way to launch the sockets server in a different thread)after which I run my rendering object's render loop and begin rendering my graphics.Now I want to pass the data coming in from my networking thread to my graphics object running on the main thread. What is the best way to do that? Some people have suggested signals2 but I can't get my head around it. How will my udp_server object have access to the signal? Should I pass it as a parameter to the udp_server object so that it can call it? (If I'm not mistaken signals cannot be copied).So the question I guess boils down to how do 2 different objects running on 2 different threads communicate via signals2 ?many thanks in advance,Jubeips.The way I'm doing it now is that I have an eventQueue object which I pass as a pointer to both to the networking object and the Ogre Application object. The networking code pushes events in the eventQueue and a custom Ogre FrameListener object polls the queue every frame for new events and pops them. Dunno if it's right but that's the only way I can think of.[Edited by - grJubei on May 13, 2010 4:01:20 AM]
Quote:Original post by grJubeiThe way I'm doing it now is that I have an eventQueue object which I pass as a pointer to both to the networking object and the Ogre Application object. The networking code pushes events in the eventQueue and a custom Ogre FrameListener object polls the queue every frame for new events and pops them. Dunno if it's right but that's the only way I can think of.I was going to jot down a few lines of code on how to do it elegantly using io_service and strands, but the edit box became crowded. So I started doing a minimal solution in Visual Studio. After 200 lines I gave up. I seemed to recall that "Java Bloated. C++ Fast".Just use eventQueue, and put a mutex around it. It's fine.   