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 6591901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:29:07+00:00 2026-05-25T17:29:07+00:00

For a certain project,I have to use the static mutex initializer in pthread.However my

  • 0

For a certain project,I have to use the static mutex initializer in pthread.However my library is supposed to be portable on Windows as well.

pthread_mutex_t csapi_mutex = PTHREAD_MUTEX_INITIALIZER;

Is there a corrosponding static initializer on windows.?

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-25T17:29:07+00:00Added an answer on May 25, 2026 at 5:29 pm

    I came up with this port of pthread-compatible mutex operations:

    #define MUTEX_TYPE             HANDLE
    #define MUTEX_INITIALIZER      NULL
    #define MUTEX_SETUP(x)         (x) = CreateMutex(NULL, FALSE, NULL)
    #define MUTEX_CLEANUP(x)       (CloseHandle(x) == 0)
    #define MUTEX_LOCK(x)          emulate_pthread_mutex_lock(&(x))
    #define MUTEX_UNLOCK(x)        (ReleaseMutex(x) == 0)
    
    int emulate_pthread_mutex_lock(volatile MUTEX_TYPE *mx)
    { if (*mx == NULL) /* static initializer? */
      { HANDLE p = CreateMutex(NULL, FALSE, NULL);
        if (InterlockedCompareExchangePointer((PVOID*)mx, (PVOID)p, NULL) != NULL)
          CloseHandle(p);
      }
      return WaitForSingleObject(*mx, INFINITE) == WAIT_FAILED;
    }
    

    Basically, you want the initialization to happen atomically when the lock is used the first time. If two threads enter the if-body, then only one succeeds in initializing the lock. Note that there is no need to CloseHandle() for the static lock’s lifetime.

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

Sidebar

Related Questions

In my AppEngine project I have a need to use a certain filter as
I have written a static library to re-use some code between iOS projects, let's
I have included three20 library in my project. I am making use of the
Is there a way to have a project use MVC1 in certain areas and
I have a web application project. I am trying to find out why certain
I'm duty-bound by policy to use CVS in this certain project, so even though
I have a fairly large C++ project, and am trying to use the debugger
I tried to use CxImage in my project VC++, however I use a walkthrough
In my project I have the requirement where certain fields depending of a certain
Hey there. I have to use the Google Chrome Frame to support certain HTML5-features

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.