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. block main thread and allow secondary to run first

block main thread and allow secondary to run first

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
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.
  • E Offline
    E Offline
    elephantstar
    wrote on last edited by
    #1

    I have an external application that launches my application. I have a global variable that determines whether my app was launched via the other app or just by opening the executable. If launched via the other application, two processes or instances gets created and the global variable is set to 1. The first instance will be created but the window frame will not be shown. The other instance will display the window. One instance has the global value initialized to 0 while the other one has it set to 1. I need to block the instance that has global variable = 0 and let the other one run. Once that thread completes, I want the other thread (I believe it’s the main thread) to continue running. I tried using a mutex around my code but it still seems to be doing context-switching. How can I put a hold on thread1? I’ve tried using events but no such luck. This is what I have. Thanks!

    InitInstance()
    {
    mutex = ::CreateMutex(NULL, FALSE, “X”);
    if(mutex==NULL)
    {
    AfxMessageBox("Error: Problem with creating the mutex");
    return FALSE;
    }
    else {
    WaitForSingleObject(mutex, INFINITE);
    if (!bGlobalVariable)
    {
    OneInstance = ::CreateMutex(NULL, FALSE, “instance”);
    DWORD dwMutexErr = GetLastError();
    if (dwMutexErr == ERROR_ALREADY_EXISTS)
    return FALSE;
    }
    ReleaseMutex(mutex);
    }

      if (!GlobalVariable)
    //show window
    return TRUE;
    

    }

    -- modifed at 17:51 Thursday 25th August, 2005

    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