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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:50:06+00:00 2026-06-15T13:50:06+00:00

Most of the examples I’m looking at on the Web have pthread_mutex_t sitting at

  • 0

Most of the examples I’m looking at on the Web have pthread_mutex_t sitting at the top of the file in the global space and I think I read somewhere that Linux mutexes have to be global. Is this true?

edit:
I have some Win32 multithreading code that I’m porting over to Linux. For the windows code, there are several wrapper functions that encapsulate things like mutex creation and locking/unlocking. My understanding is that every synchronization primitive that’s created through one of the Create() API calls in Windows returns a HANDLE that can be stored in an instance field and then used later. In this case, it’s used in the Lock() function, which is wrapper around WaitForSingleObject(). For Linux, could I simply store the mutex in an instance field and call pthread_mutex_lock()/pthread_cond_wait() in the Lock() function and expect the same behavior as on Windows?

Nv_Mutex::Nv_Mutex(Nv_XprocessID name)
{

#if defined(WIN32)
    if((handle = ::CreateMutexA(0, false, name)) == NULL)
    {
        throw Nv_EXCEPTION(XCPT_ResourceAllocationFailure, GetLastError());
    }

    isCreator = !(::GetLastError() == ERROR_ALREADY_EXISTS);
#else
    if (name == Nv_XprocessID_NULL) {
        /*
        pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;                     // Fast
        pthread_mutex_t recmutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;     // Recursive
        pthread_mutex_t errchkmutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP; // Errorcheck
        */
        mutex = PTHREAD_MUTEX_INITIALIZER;
        // attributes??

        if (pthread_mutex_init(&mutex, NULL) != 0) {
            throw Nv_EXCEPTION(XCPT_ResourceAllocationFailure, GetLastError());
        }
    }
    else {
        // insert code for named mutex (needed for shared mutex across processes) here.
    }

    //isCreator = !(GetLastError() == EBUSY);
#endif
}

bool                
Nv_Mutex::Lock(const char *f, int l, Nv_uint32 timeout)
{

    switch(WaitForSingleObject(handle, timeout))
    {
        case WAIT_OBJECT_0:
            file = f;
            line = l;
            return true;

        case WAIT_TIMEOUT:
            return false;
    }

    throw Nv_EXCEPTION(XCPT_WaitFailed, GetLastError());
}
  • 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-06-15T13:50:07+00:00Added an answer on June 15, 2026 at 1:50 pm

    No, they can scoped. There is nothing special about the actual mutex pointer.

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

Sidebar

Related Questions

Most examples use time-based cache expiration. I'd like to read more about file caches
In most examples that you find on the web when explicitly not using using,
Most examples I see about hosting WCF in IIS have you create an Application
I have looked at the network documentation for Unity and most examples seem to
I am new to directx, but have been surprised that most examples I have
Most examples I've seen have scripts in a html page being enclosed by <!--
Most examples of inplace editing are one-liners that iterate through a file or files,
Most examples I have found use Trace.WriteLineIf e.g. `Trace.WriteLineIf(mySwitch.TraceError,my error);' but using Trace.TraceError(my error);
Most examples of bundle identifiers have three parts. Are four part bundle identifiers valid
Most examples show how to redirect all subdomain traffic to a primary domain, maintaining

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.