Race conditions
-
Two days ago I had to send out an application. At the very last minute I was asked if I could add a splash screen to it and stupid me said yes. I had never done that before in my life. I tried to add a splash screen through Components and Controls but that works only for MDI or SDI. My application is dialog based. With only 20 minutes left (I couldn't go online and search codeproject) I decided to add my own splash screen. So inside OnInitDialog I have something like this:
CSplashDlg aSplashDlg( this );
aSplashDlg.DoModal()Not being able to send a close message to CSplashDlg I just added a thread to CSplashDlg (a CDialog based class).
UINT SplashDelayThread( LPVOID pParam )
{
Sleep( 5000 );
::PostMessage( (HWND)pParam, WM_CLOSE, 0, 0 );
return 0;
}int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;// TODO: Add your specialized creation code here AfxBeginThread( SplashDelayThread, this->m\_hWnd, THREAD\_PRIORITY\_NORMAL ); return 0;
}
Now I am afraid that this might cause race conditions. For example what if the thread is activated and then it returns before the Splash dialog is created. 5 seconds is a long time but should I be worried? I mean you never know. // Afterall, I realized that even my comment lines have bugs