40media waiting for 2 different events in a single thread

waiting for 2 different events in a single thread

REMOVED - reason: not really needed.

my questions are:

  • can I use a linux UDP socket from two different threads? answer was here
  • I have two different events I would like to wait for using just one thread. One of such events is the addition of an element to a stack and another is the availability of data on a socket.
    I can use a 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?
  • Is there any other alternative solution for this problem that I'm not aware of? - I'll figure this one out by myself.

Program to open large MySQL dumps


Finding an available network port on the machine

New Answer

But there is no mechanism (this I am aware of) this allows me to wait for both events at the same time (polling is out of the question). Monitor file in Java on Linux 64bitsOr is it?. Preventing multiple process instances on Linux
Not this I'm aware of, and not without polling... Control Debug Level in C++ Library - Linuxyou'll need a thread to wait for each asynchronous event. Is there a difference calling daemon(0,0) from within a program, and launching a program to be in background and redirecting it's outputYou must use a blocking stack or like you said use boost::condition_variable which blocks until there is any thing on the stack. Reporting library for Linux / C++ / Gtk? [closed]The boost::asio::io_service will be very useful for managing the udp sockets, although it doesn't actually commit you any advantage when it comes to the event handling.. ether_ntoa pointers cast problem

Old Answer

I'm REALLY not sure what you're endeavor to do... what you're saying doesn't make enough sense. I'll did my best to guess what you're endeavor to do, although 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 must I did it from the new-thread? (I think the answer is no, although I'm not sure around 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 this 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 did two things at the same time in the same thread... with this said you have two options:.
  1. Constantly poll to see if either event has occurred (on the same thread).
  2. Have two threads this are blocking until a desired event occurs (usually when you read from a socket it blocks if there is no data).
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 commit us a very simple case of code this i must follow.. Question:.
Is there any another alternative quick fix for this problem this I'm not aware of?.
Answer: There are always alternative solutions out there, although it's really difficult to tell what the alternatives might be given the current description of the "problem." I think this you should edit the problem again and focus on providing very concrete examples, perhaps any pseudid code, etc..


Switch to Windows and use WaitForMultipleObjects, or receive this function implemented in Linux. It's quite handy, and then you must did two things on the same thread..

74 out of 100 based on 59 user ratings 734 reviews