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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:21:43+00:00 2026-06-04T14:21:43+00:00

According to Boost documentation boost::mutex and boost::timed_mutex are supposed to be different. The first

  • 0

According to Boost documentation boost::mutex and boost::timed_mutex are supposed to be different. The first one implements Lockable Concept, and the second – TimedLockable Concept.

But if you take a look at the source, you can see they’re basically the same thing. The only difference are lock typedefs. You can call timed_lock on boost::mutex or use boost::unique_lock with timeout just fine.

typedef ::boost::detail::basic_timed_mutex underlying_mutex;
class mutex:
    public ::boost::detail::underlying_mutex

class timed_mutex:
    public ::boost::detail::basic_timed_mutex

What’s the rationale behind that? Is it some remnant of the past, is it wrong to use boost::mutex as a TimedLockable? It’s undocumented after all.

  • 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-04T14:21:45+00:00Added an answer on June 4, 2026 at 2:21 pm

    I have not looked at the source, but I used these a few days ago, and the timed mutexes function differently. They block until the time is up, then return. A unique lock will block until it can get the lock.

    A try lock will not block, and you can then test to see if it has ownership of the lock. A timed lock will block for the specified amount of time, then behave as a try lock – that is, cease blocking, and you can test for ownership of the lock.

    I believe that internally some of the different boost locks are typedefs for unique lock since they all use unique locking. The typedef names are there so that you can keep track of what you are using different ones for, even though you could use different functionality and confuse your client code.

    Edit: here is an example of a timed lock:

    boost::timed_mutex timedMutexObj;
    boost::mutex::scoped_lock scopedLockObj(timedMutexObj, boost::get_system_time() + boost::posix_time::seconds(60));
    if(scopedLockObj.owns_lock()) {
        // proceed
    }
    

    For reference: http://www.boost.org/doc/libs/1_49_0/doc/html/thread/synchronization.html#thread.synchronization.mutex_concepts.timed_lockable.timed_lock

    Edit again: to provide a specific answer to your question, yes, it would be wrong to use boost::mutex as a TimedLockable because boost::timed_mutex is provided for this purpose. If they are the same thing in the source and this is undocumented, this is unreliable behavior and you should follow the documentation. (My code example did not used timed_mutex at first but I updated it)

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

Sidebar

Related Questions

According to the documentation , a boost::thread::id can be considered unique for each running
According to the Boost Documentation , having multiple threads call io_service::run() sets up a
why is this (pagefile.sys) file not a regular file according to boost::filesystem? I've created
I am trying to overload operators of a C++ class using Boost.Python. According to
I'm renaming a file using boost::filesystem, and sometimes the target file will exist. According
I'm using a Boost multi_index container to store objects according to 2 integer keys
I'm getting started with Boost::Test driven development (in C++), and I'm retrofitting one of
Can anyone discern what I'm doing wrong here? According to the documentation in 1.47
According to ADC documentation: You can access Open Firmware this by holding down Command-Option-O-F
I need to embed Boost headers in my project. According to this question ,

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.