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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:21:00+00:00 2026-05-30T18:21:00+00:00

I am trying to use std::atomic library. What’s the difference between specialized and non-specialized

  • 0

I am trying to use std::atomic library.

  1. What’s the difference between specialized and non-specialized atomic
    member functions?
  2. What’s the difference (if there is any) between following functions?
  3. operator= stores a value into an atomic object (public member function) v.s. store (C++11) atomically replaces the value of the atomic object with a non-atomic argument (public member function)
  4. operator T() loads a value from an atomic object (public member function) v.s. load (C++11) atomically obtains the value of the atomic object (public member function).
  5. operator+= v.s. fetch_add
  6. operator-= v.s. fetch_sub
  7. operator&= v.s. fetch_and
  8. operator|= v.s. fetch_or
  9. operator^= v.s. fetch_xor
  10. What’s the downside of declare a variable as atomic v.s. a
    non-atomic variable. For example, what’s the downside of
    std::atomic<int> x v.s. int x? In other words, how much is the overhead of an atomic variable?
  11. Which one has more overhead? An atomic variable, v.s. a normal
    variable protected by a mutex?

Here is the reference to my quesitons. http://en.cppreference.com/w/cpp/atomic/atomic

  • 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-30T18:21:02+00:00Added an answer on May 30, 2026 at 6:21 pm

    Not an expert, but I’ll try:

    1. The specializations (for built-in types such as int) contain additional operations such as fetch_add. Non-specialized forms (user defined types) will not contain these.
    2. operator= returns its argument, store does not. Also, non-operators allow you to specify a memory order. The standard says operator= is defined in terms of store.
    3. Same as above, although it returns the value of load.
    4. Same as above
    5. Same as above
    6. Same as above
    7. Same as above
    8. Same as above
    9. Same as above
    10. They do different things. It’s undefined behavior to use an int in the way you would use std::atomic_int.
    11. You can assume the overhead is int <= std::atomic <= int and std::mutex where <= means ‘less overhead’. So it’s likely better than locking with a mutex (especially for built-in types), but worse than int.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use an unordered_set from the C++ std library. I am
I'm trying to use BOOST_FOREACH for iterating through the std::queue. But there isn't iterators
I am trying to use std::shared_ptr in my code. I have seen there have
I'm trying to use the C++ STD TechnicalReport1 extensions to generate numbers following a
We are trying to use the std::deque erase member function. The return value of
I'm trying to use std::string instead of char* whenever possible, but I worry I
I'm trying to use templates to get std:list of items, where each item has
I'm trying to use openmp to multithread a loop through std::set. When I write
I'm trying to use stl algorithm for_each without proliferating templates throughout my code. std::for_each
I was trying use a set of filter functions to run the appropriate routine,

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.