c++windowsboost

Boost Equivalent for Windows Events


In windows c++ I can create a handle to event

Handle h = CreateEvent(...)

I can then set and reset that event

SetEvent(...) and ResetEvent(...)

Finally, I can OpenEvents using the command OpenEvent(...)

Is there a boost equivelent for events?


Solution

  • I think you need to use boost::mutex, boost::unique_lock, boost::condition_variable and possibly bool in order to imitate Events.

    You actually might need sort of WaitForSingleObject in order to wait for an event. Might be like this:

    void wait_for_user_input()
    {
        boost::unique_lock<boost::mutex> lock(mut);
        while(!data_ready)
        {
            cond.wait(lock);
        }
        process_user_input(); // it might be not necessary to hold mutex locked here!!!
                              // if so just add curly braces like this:
                              // void wait_for_user_input()
                              // {
                              //    { 
                              //      boost::unique_lock<boost::mutex> lock(mut);
                              //      while(!data_ready) { cond.wait(lock); }
                              //    }
                              //    process_user_input();
                              // }
    
    
    
    }