Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Race conditions

Race conditions

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Toni78
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups