Reputation: 6456
REMOVED - reason: not really needed.
my questions are:
boost::condition_variable.wait(lock)
for the stack and boost::asio::io_service
for the socket. But there is no mechanism (that I am aware of) that allows me to wait for both events at the same time (polling is out of the question). Or is it?Upvotes: 0
Views: 1093
Reputation: 3482
Switch to Windows and use WaitForMultipleObjects, or get this function implemented in Linux. It's quite handy, and then you can do two things on the same thread.
Upvotes: 0
Reputation: 40345
But there is no mechanism (that I am aware of) that allows me to wait for both events at the same time (polling is out of the question). Or is it?
Not that I'm aware of, and not without polling... you'll need a thread to wait for each asynchronous event. You can use a blocking stack or like you said use boost::condition_variable
which blocks until there is something on the stack. The boost::asio::io_service
will be very useful for managing the udp sockets, but it doesn't actually give you any advantage when it comes to the event handling.
I'm REALLY not sure what you're trying to do... what you're saying doesn't make much sense. I'll do my best to guess what you're trying to do, but I would suggest clarifying the question.
Question:
Do I really need to use the main thread to send the data over component A socket or can I do it from the new-thread? (I think the answer is no, but I'm not sure about race conditions on sockets)
Answer:
You don't have to use the main thread to send data over the given component's socket. Now depending on the socket library you're using there might be different restrictions: you may only be able to send data on the same thread that the socket was created, or you might be able to send data from any thread... it really depends on the implementation of your socket.
Question:
how to I wait for both events?
Answer:
You can't do two things at the same time in the same thread... with that said you have two options:
Given the description of your problem it's unclear what you would achieve by using boost::condition_variable
and/or boost::asio::io_service
. Perhaps you should give us a very simple example of code that we can follow.
Question:
Is there any other alternative solution for this problem that I'm not aware of?
Answer:
There are always alternative solutions out there, but it's really difficult to tell what the alternatives might be given the current description of the "problem." I think that you should edit the problem again and focus on providing very concrete examples, perhaps some pseudo code, etc.
Upvotes: 1