Have your background thread set a flag to a mutexed variable on your main thread which tells it (the main thread) that it is safe to continue doing whatever it is doing. It's sort of like a stop light -- all corners (both sides) have lights that are inter-related.
Your main thread will not pause, but you can have a while loop where you handle (gui and other) messages but it won't break the loop until the mutexed variable get's set -- and that will occur on the background thread.
Here are some references to get you started:
EDIT -- Per request:
Globally, define your mutex handle and your variable:
HANDLE sharedMemoryMutex = CreateMutex(NULL, FALSE, "My mutex =)!");
BOOL good2Go = false;
Then, in your background thread, it will look something like this:
void wait() {
// First, we sleep...
sleep(3000);
// Now, we request a lock on the good2Go variable, so that when we write to
// it, no other thread is:
DWORD dwWaitResult = WaitForSingleObject(sharedMemoryMutex, INFINITE);
if (dwWaitResult == WAIT_OBJECT_0 || dwWaitResult == WAIT_ABANDONED) {
if (dwWaitResult == WAIT_ABANDONED) {
// Shared memory is maybe in inconsistent state because other program
// crashed while holding the mutex. Check the memory for consistency
...
}
// Access your shared memory
good2Go = true;
// Release the lock so that the main thread can read the variable again..
ReleaseMutex(sharedMemoryMutex);
}
Then in your main thread, it will look something like this:
// Create your background wait thread:
// .....
while(true) {
// Handle messages so that your program doesn't appear frozen.
// You will have to do your research on this one =)
YourMessageHandler();
// Request a lock on the good2Go variable, so we can read it w/o corrupting it
DWORD dwWaitResult = WaitForSingleObject(sharedMemoryMutex, INFINITE);
if (dwWaitResult == WAIT_OBJECT_0 || dwWaitResult == WAIT_ABANDONED) {
if (dwWaitResult == WAIT_ABANDONED) {
// Shared memory is maybe in inconsistent state because other program
// crashed while holding the mutex. Check the memory for consistency
...
}
// Exit the loop
if( good2Go ) { ReleaseMutex(sharedMemoryMutex); break; }
ReleaseMutex(sharedMemoryMutex);
}
// Continue your code after the 3 pause....
You will have to figure out how to handle messages if you do not know already. Also, your mutex implementation may be different, however you said you're using VC so the above win32 implementation should be okay. And I think you understand the general concept