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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:23:41+00:00 2026-05-22T03:23:41+00:00

How does mutex scope work exactly. If I want 3 mutexes for different things

  • 0

How does mutex scope work exactly.

If I want 3 mutexes for different things and place them as so

static pthread_mutex_t watchdogMutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t watchdogCond = PTHREAD_COND_INITIALIZER;
int waitingForGpsSetupThread = 1;

static pthread_mutex_t gpsRunningMutex = PTHREAD_MUTEX_INITIALIZER;
int gpsRunning = 0;

static pthread_mutex_t indoorNavigationRunningMutex = PTHREAD_MUTEX_INITIALIZER;
int indoorSystemRunning = 0;

Are the variables defined within the scope of the first above mutex declaration or how does it work?

  • 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-22T03:23:41+00:00Added an answer on May 22, 2026 at 3:23 am

    As written, the three mutexes are all in the same scope. There are no blocks marked by ‘{…}’ to indicate otherwise. The same would be true if the types were all int. From that point of view, a mutex is no different from any other type.

    At the point of use, you would do something like:

    pthread_mutex_lock(&watchdogMutex);
    
    ...operations protected by the watchdog mutex...
    
    pthread_mutex_unlock(&watchdogMutex);
    

    The bit in the middle could be said to be the scope in which the mutex is locked. It would be a very bad idea to have a return statement in the middle of those operations – unless the mutex was also unlocked before returning.

    See the POSIX definitions.

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

Sidebar

Related Questions

how does a mutex can be shared between processes? does it mean a different
Does anyone know how to get IntelliSense to work reliably when working in C/C++
Does mutex guarantee to execute thread in order of arriving? that is, if, thread
Does anyone know if when creating a mutex, it's a must to initialize it
Does the POSIX standard allow a named shared memory block to contain a mutex
The documentation for RegisterWaitForSingleObject says Using a Mutex for waitObject does not provide mutual
EDIT : It seems BCP does what I want: Building a subset of boost
The Mutex class is very misunderstood, and Global mutexes even more so. What is
What data type is a mutex? I want to set an int as a
Let's say I'm programming in a threading framework that does not have multiple-reader/single-writer mutexes

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.