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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:07:24+00:00 2026-05-30T04:07:24+00:00

I am very confused about the difference between a lock and mutex. In Boost

  • 0

I am very confused about the difference between a lock and mutex. In Boost docs, it says,

Lock Types

  • Class template lock_guard
  • Class template unique_lock
  • Class template shared_lock
  • Class template upgrade_lock
  • Class template upgrade_to_unique_lock
  • Mutex-specific class scoped_try_lock

Mutex Types

  • Class mutex
  • Typedef try_mutex
  • Class timed_mutex
  • Class recursive_mutex
  • Typedef recursive_try_mutex
  • Class recursive_timed_mutex
  • Class shared_mutex

In another article, I see functions like this,

boost::shared_mutex _access;
void reader()
{
  boost::shared_lock< boost::shared_mutex > lock(_access);
  // do work here, without anyone having exclusive access
}    
void conditional_writer()
{
  boost::upgrade_lock< boost::shared_mutex > lock(_access);
  // do work here, without anyone having exclusive access

  if (something) {
    boost::upgrade_to_unique_lock< boost::shared_mutex > uniqueLock(lock);
    // do work here, but now you have exclusive access
  }
  // do more work here, without anyone having exclusive access
}

Updated questions

  1. Can anyone offer some clarification between the “mutex” and “lock”?
  2. Is it necessary to create a shared_lock for a shared_mutex?
    What happen if I create a unique_lock for a shared_mutex?
  3. Or if I create a shared_lock for a mutex, does it mean the mutex can
    not be shared among multiple threads?
  • 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-30T04:07:25+00:00Added an answer on May 30, 2026 at 4:07 am

    A mutex is a synchronization object. You acquire a lock on a mutex at the beginning of a section of code, and release it at the end, in order to ensure that no other thread is accessing the same data at the same time. A mutex typically has a lifetime equal to that of the data it is protecting, and that one mutex is accessed by multiple threads.

    A lock object is an object that encapsulates that lock. When the object is constructed it acquires the lock on the mutex. When it is destructed the lock is released. You typically create a new lock object for every access to the shared data.

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

Sidebar

Related Questions

This question expands upon the one at abstract-class-numberformat-very-confused-about-getinstance . I feel that this question
Hey everybody, I'm very confused about how to use two different Cell Types in
I'm very confused about the whole user profile thing in drupal, hope someone can
I'm VERY confused as to why this code Html.ActionLink(About, About, Home, new { hidefocus
Ok, I'm now very confused. After my last question had several people comment about
I have read the docs and everything but I'm very confused. I never needed
I am very confused about the const version and non-const version member function like
I am very confused about how constructors work in JavaScript; despite using the language
What the different between ./ vs ../ vs / I'm very confused, i tried
I am using windows form and mysql. I am very confuse about different between

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.