Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6714585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:30:46+00:00 2026-05-26T08:30:46+00:00

Here is the snippet: prog1: HANDLE hM; hM = CreateMutexA(NULL,TRUE, abc); // I have

  • 0

Here is the snippet:
prog1:

HANDLE hM;
hM = CreateMutexA(NULL,TRUE, "abc"); // I have to use TRUE otherwise WaitForSingleObject fails.. by design it wants to take ownership and w//o TRUE there is no owner anyway right? <<-- **check this please if its true**
...

prog2:

HANDLE hM;
hM = OpenMutexA(MUTEX_ALL_ACCESS,NULL, "abc");
while(WaitForSingleObject(hM,INFINITE)) {
// do smthing
ReleaseMutex(hM);
hM = OpenMutexA(MUTEX_ALL_ACCESS,NULL, "abc"); // In order to continue while loop but it doesnt rewind,
}

Issue> It won’t make semi-infinite loop … it enters once and thats it.

Purpose? To monitor activity of some process (if it crash I restart it), infinite loops are hitting my CPU hard and I cant use Sleep, I need to restart it asasp (well if some smart solution is possible via while(1) or for(;;) please post)

UPDATE

should be while(WaitForSingleObject(hM,INFINITE) == WAIT_ABANDONED){ … }, I didnt copy correctly :).

It works once and then it won’t wait again, is there a way to reset handle?


prog1:

HANDLE hM;
hM = CreateMutexA(NULL,TRUE, "abc");

prog2:

HANDLE hM;
hM = OpenMutexA(MUTEX_ALL_ACCESS,NULL, "abc");
while(WaitForSingleObject(hM,INFINITE)) {    
ReleaseMutex(hM);
Sleep(1000);
CloseHandle(hM)
// do smthing like CreateProcess()
Sleep(1000);
hM = OpenMutexA(MUTEX_ALL_ACCESS,NULL, "abc");
}

This way it works, if anyone wants to add something comment on this post.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:30:47+00:00Added an answer on May 26, 2026 at 8:30 am

    To detect process crash, you shouldn’t bother with a mutex. Just wait on the process handle. Once the process exits, the handle will be signaled, and WaitForSingleObject will return.

    If you’re creating the process, you can get the process handle from the PROCESS_INFORMATION argument. Then, just use:

    PROCESS_INFORMATION pi;
    
    do {
    // create the process, passing pi as the last argument to CreateProcess
    } while (WaitForSingleObject(pi.hProcess, INFINITE));
    

    Note that the handle should be closed, you can figure out when.


    Update – Given this is not an option, here’s the problem in your code:

    Say prog1 started successfully, and prog2 is now waiting for the mutex to be signaled. Then prog1 crashes, and prog2 gets to own the mutex. Given prog2’s purpose is to relaunch prog1, I assume this is what happens in // do smthing. So now prog1 starts, and calls CreateMutexA. But prog2 might still be holding the mutex, and so prog1 only gets a handle to the existing mutex, but it doesn’t actually own it. Now prog2 calls ReleaseMutex, and continues to a wait on a signaled mutex, which is not owned by prog1. The wait immediately returns with WAIT_OBJECT_0, and you get out of the while.

    So, I think prog1’s use of CreateMutexA is wrong here. You should instead create an un-owned mutex, and wait on it. This way, you’ll ensure prog1’s ownership of the mutex.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found a code snippet here , which I wanted to use, but I
We use spring to construct/inject our java beans. Here a snippet: <bean id=myAppConfigs class=my.cool.webapp.ApplicationConfig
Here's the snippet of html i have: <div id=tag-cloud-widget> <div class=content> <a href=# rel=1
I am working with Ruby scripting language. I have a snippet here. Just want
I have this little snippet here, and it returns false even if it satisfies
Here's a snippet from my application: class PortolioItem(models.Model): ... user = models.ForeignKey(User) contract =
Here's a snippet of a script of mine attempting to put extra Unicode awesomeness
Here is a snippet of the official Apple Documentation of AudioBufferList (Core Audio Data
Here is a snippet of my code $fp = fsockopen($s['url'], 80, $errno, $errstr, 5);
Here is a snippet from a Sinatra app where users will be submitting urls.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.