I'm using an ExNotifyCallback function to signal from one component to another. There are several instances listening to this CB and only the proper one will respond. The response comes via a call through a separate function pointer interface:
void (*pfnResponseFunc)(void*pData, int* pDataSize)
I want to issue the ExNotifyCallback and then wait for a response coming through the pfnResponseFunc.
Code flow that would occur in a function:
// Send message to listeners:
ExNotifyCallback(myCbObject, pIn1, pIn2);
// Wait (with timeout) for pfnResponseFunc to get called...
if (responseFound)
{
// read pData that showed up in pfnResponseFunc, return success
}
else
{
// return failure
}
I want this to specifically wait for a fixed timeout in the same function. Is there a typical way to do this in windows?
The basic solution has two parts:
I think I normally would use an event for this, to signal between multiple components.
Then, your components can wait for the event using WaitForSingleObject, which has a timeout in MS.
There is a lot of detail you are missing here though.
Anyway, there are many concurrency patterns you can use depending on what you want to do, but using events and the threadpool is the typical way of going about it.