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

  • SEARCH
  • Home
  • 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 6060365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:49:02+00:00 2026-05-23T08:49:02+00:00

According to http://msdn.microsoft.com/en-us/library/ms687032%28v=vs.85%29.aspx , WaitForSingleObject() has undefined behavior if a handle gets closed while

  • 0

According to http://msdn.microsoft.com/en-us/library/ms687032%28v=vs.85%29.aspx, WaitForSingleObject() has undefined behavior if a handle gets closed while waiting on it.

Because we can’t tell the order by which static variables are disposed, is it safe to declare a mutex as a static variable with file scope?

namespace
{
    static HANDLE g_hMutex = CreateMutex(NULL, FALSE, NULL);
}

int CMyClass::Foo() //CMyClass is a singleton
{
    int ret = 0;
    if (WaitForSingleObject(g_hMutex, 1000) != WAIT_OBJECT_0)
        return -1;

    //Do something

    ReleaseMutex(g_hMutex);
    return ret;
}

Thanks!

  • 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-23T08:49:02+00:00Added an answer on May 23, 2026 at 8:49 am

    I would be very leery about calling any Win32 API function at namespace scope. Also, since you have to release it in your function anyway, why not allocate it there too? It’s much more symmetrical that way.

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

Sidebar

Related Questions

According to http://msdn.microsoft.com/en-us/library/aa916070.aspx (DnsQuery_W), DNS query libraries are available on Windows Mobile / CE
First off, according to http://msdn.microsoft.com/en-us/library/x0b5b5bc.aspx , the List.Find method is only listed as throwing
According to [MSDN: Array usage guidelines]( http://msdn.microsoft.com/en-us/library/k2604h5s(VS.71).aspx) : Array Valued Properties You should use
According to http://msdn.microsoft.com/en-us/library/aa984351%28VS.71%29.aspx Disabling the first or toplevel menu item in a menu (for
According to this: http://www.codeplex.com/IronPython/Wiki/View.aspx?title=IP20VsCPy25Perf&referringTitle=IronPython%20Performance IronPython (Python for .Net) is faster than regular Python (cPython)
I am using a technique similar to http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/df77a277-91d4-41f1-a42a-0fa02a443ff4/ I have a DaataGridTemplateColumn built, in
According to this http://www.cplusplus.com/reference/clibrary/csignal/signal.html SIGINT is generally used/cause by the user. How do i
According to google and some other sources (e.g., http://www.enterprisedt.com/publications/oracle/result_set.html ), if I want to
From Don Syme blog ( http://blogs.msdn.com/b/dsyme/archive/2010/01/10/async-and-parallel-design-patterns-in-f-reporting-progress-with-events-plus-twitter-sample.aspx ) I tried to implement a twitter stream
According to http://docs.jquery.com/Plugins/Validation the form tag is necessary in order to do validation. In

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.