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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:02:53+00:00 2026-06-15T17:02:53+00:00

In the Boost 1.5.1 source under smart_ptr\detail\atomic_count_win32.hpp is a neat little atomic reference counter

  • 0

In the Boost 1.5.1 source under smart_ptr\detail\atomic_count_win32.hpp is a neat little atomic reference counter boost::detail::atomic_count.

on line 48, they do a cast I’m curious about:

class atomic_count
{
public:

// ...

operator long() const
{
    return static_cast<long const volatile &>( value_ );
}

private:
long value_;

Why is the counter value cast to a-reference-to-a-volatile-constant-long (long const volatile&)?

  • 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-15T17:02:54+00:00Added an answer on June 15, 2026 at 5:02 pm

    MSVC provides a now-deprecated extension on volatile variables, giving them acquire and release semantics (memory ordering guarantees, with respect to multithreaded programming.)

    This cast “enables” this extension on the variable, giving it read-acquire semantics (to match any release-writes that may also occur). Again, this is, non-standard. In C++11 code you should use std::atomic<>.

    They need this because boost::shared_ptr gives guarantees of correctness for shared_ptr<T> in multithreaded (shared) use; this is their implementation of a lock-free counter.

    (Also, this is only half the story: while this extension may provide the needed ordering and visibility guarantees, it does not guarantee atomicity. On Win32 this is guaranteed implicitly by the platforms it runs on: aligned word-sized integer reads and writes are atomic per the platform.)

    To nip it in the bud before it starts: without this extension volatile is not useful for multithreaded programming. Don’t even try. This extension is deprecated, so you should really avoid it if you can.

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

Sidebar

Related Questions

I'm using Boost Spirit to parse source files in a little compiler project. If
I installed Boost and have the code #include <boost/initial_path.hpp> in my source and it
I'm looking for documentation on boost::threadpool. I downloaded the source and documentation zip files.
// BOOST Includes #include <boost/assign.hpp> // Boost::Assign #include <boost/assign/list_of.hpp> // Boost::Assign::List_Of #include <boost/assign/std/map.hpp> //
Is it allowed by the Boost License to just add the source code of
Without spending a long time reviewing the boost source code, could someone give me
I use MinGW on Windows. I get the boost source files from svn and
Is there a way to exclude boost source code (or any other) from debuging?
I downloaded Boost v1.42 source and then installed it in my laptop. I want
So I was looking through some boost source code and came across this: (from

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.