I would like to make a function to lock until a certain event is triggered.
The point is that I'm sending some data to a socket and the reception is done asynchronously by a socket receiver thread. When the result is available, onReceive() function of my class is called by the thread.
I would like my sending function to return only when the result is available, meaning that onReceive is called.
I tried to create am object (using CreateSemaphore) and use the WaitForSingleObject method to wait until the object becomes signaled. The onReceive method should set the object's state to signeld, but this is not happening and my function will deadlock.