Definition of “atomic object”

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












21















In standard jargon of C and C++, the phrase "atomic object" means "object of atomic type," does it not?



No standard will explicitly define every two-word phrase, so one does not fault the C and C++ standards for omitting explicit definition of this one. Nevertheless, when I read in the C++17 standard (draft here), sect. 4.7.1(4), that "all modifications to a particular atomic object M occur in some particular total order, called the modification order of M"—and when the standard repeatedly employs similar language to delimit ever more precise logic for concurrency—I would like to be sure that I am not inadvertently misunderstanding.



Do I assume correctly that the phrase "atomic object" means




  • object of atomic type?

The only plausible alternative I can imagine would be that the phrase instead meant



  • properly aligned object small enough that hardware could handle it atomically.

Which is it, please?



(Note: I tag this question both C and C++ because, when it comes to atomics, the two standards use almost identical language. For this reason, an expert in either language can answer as far as I know. If for some reason I am mistaken, then please remove the C tag and retain the C++.)



Reference: see also this question, for which my question is preliminary.










share|improve this question

















  • 2





    Modern C and C++ have an atomic keyword, which is a type qualifier just like const. So I would assume atomic object means "an atomic-qualified object". That is, declared as (C11) _Atomic int blondie; with the _Atomic type qualifier.

    – Lundin
    Feb 26 at 12:35







  • 15





    @Lundin C++ does not have an atomic keyword.

    – eerorika
    Feb 26 at 12:36






  • 9





    @eerorika Well whatever, std::atomic<int> template fluff.

    – Lundin
    Feb 26 at 12:37






  • 1





    For C11, see: port70.net/~nsz/c/c11/n1570.html#6.2.5p20; port70.net/~nsz/c/c11/n1570.html#6.2.5p27; port70.net/~nsz/c/c11/n1570.html#6.2.6.1p9; port70.net/~nsz/c/c11/n1570.html#6.5.2.3p5; port70.net/~nsz/c/c11/n1570.html#6.5.2.4p2; port70.net/~nsz/c/c11/n1570.html#6.7.2.4; port70.net/~nsz/c/c11/n1570.html#6.7.3; Atomics <stdatomic.h>. And probably other places — there are lots of mentions of atomic in the standard linked to. C18 is very similar, though atomic figure in the changes.

    – Jonathan Leffler
    Feb 26 at 12:46







  • 1





    Atomic object is not necessarily an object of std::atomic type (at least in C++20). New std::atomic_­ref class template makes an object it refers to atomic. … for the lifetime of the atomic_­ref object, the object referenced by *ptr is an atomic object. Whether such wording is optimal is another question.

    – Language Lawyer
    Feb 26 at 13:20
















21















In standard jargon of C and C++, the phrase "atomic object" means "object of atomic type," does it not?



No standard will explicitly define every two-word phrase, so one does not fault the C and C++ standards for omitting explicit definition of this one. Nevertheless, when I read in the C++17 standard (draft here), sect. 4.7.1(4), that "all modifications to a particular atomic object M occur in some particular total order, called the modification order of M"—and when the standard repeatedly employs similar language to delimit ever more precise logic for concurrency—I would like to be sure that I am not inadvertently misunderstanding.



Do I assume correctly that the phrase "atomic object" means




  • object of atomic type?

The only plausible alternative I can imagine would be that the phrase instead meant



  • properly aligned object small enough that hardware could handle it atomically.

Which is it, please?



(Note: I tag this question both C and C++ because, when it comes to atomics, the two standards use almost identical language. For this reason, an expert in either language can answer as far as I know. If for some reason I am mistaken, then please remove the C tag and retain the C++.)



Reference: see also this question, for which my question is preliminary.










share|improve this question

















  • 2





    Modern C and C++ have an atomic keyword, which is a type qualifier just like const. So I would assume atomic object means "an atomic-qualified object". That is, declared as (C11) _Atomic int blondie; with the _Atomic type qualifier.

    – Lundin
    Feb 26 at 12:35







  • 15





    @Lundin C++ does not have an atomic keyword.

    – eerorika
    Feb 26 at 12:36






  • 9





    @eerorika Well whatever, std::atomic<int> template fluff.

    – Lundin
    Feb 26 at 12:37






  • 1





    For C11, see: port70.net/~nsz/c/c11/n1570.html#6.2.5p20; port70.net/~nsz/c/c11/n1570.html#6.2.5p27; port70.net/~nsz/c/c11/n1570.html#6.2.6.1p9; port70.net/~nsz/c/c11/n1570.html#6.5.2.3p5; port70.net/~nsz/c/c11/n1570.html#6.5.2.4p2; port70.net/~nsz/c/c11/n1570.html#6.7.2.4; port70.net/~nsz/c/c11/n1570.html#6.7.3; Atomics <stdatomic.h>. And probably other places — there are lots of mentions of atomic in the standard linked to. C18 is very similar, though atomic figure in the changes.

    – Jonathan Leffler
    Feb 26 at 12:46







  • 1





    Atomic object is not necessarily an object of std::atomic type (at least in C++20). New std::atomic_­ref class template makes an object it refers to atomic. … for the lifetime of the atomic_­ref object, the object referenced by *ptr is an atomic object. Whether such wording is optimal is another question.

    – Language Lawyer
    Feb 26 at 13:20














21












21








21


3






In standard jargon of C and C++, the phrase "atomic object" means "object of atomic type," does it not?



No standard will explicitly define every two-word phrase, so one does not fault the C and C++ standards for omitting explicit definition of this one. Nevertheless, when I read in the C++17 standard (draft here), sect. 4.7.1(4), that "all modifications to a particular atomic object M occur in some particular total order, called the modification order of M"—and when the standard repeatedly employs similar language to delimit ever more precise logic for concurrency—I would like to be sure that I am not inadvertently misunderstanding.



Do I assume correctly that the phrase "atomic object" means




  • object of atomic type?

The only plausible alternative I can imagine would be that the phrase instead meant



  • properly aligned object small enough that hardware could handle it atomically.

Which is it, please?



(Note: I tag this question both C and C++ because, when it comes to atomics, the two standards use almost identical language. For this reason, an expert in either language can answer as far as I know. If for some reason I am mistaken, then please remove the C tag and retain the C++.)



Reference: see also this question, for which my question is preliminary.










share|improve this question














In standard jargon of C and C++, the phrase "atomic object" means "object of atomic type," does it not?



No standard will explicitly define every two-word phrase, so one does not fault the C and C++ standards for omitting explicit definition of this one. Nevertheless, when I read in the C++17 standard (draft here), sect. 4.7.1(4), that "all modifications to a particular atomic object M occur in some particular total order, called the modification order of M"—and when the standard repeatedly employs similar language to delimit ever more precise logic for concurrency—I would like to be sure that I am not inadvertently misunderstanding.



Do I assume correctly that the phrase "atomic object" means




  • object of atomic type?

The only plausible alternative I can imagine would be that the phrase instead meant



  • properly aligned object small enough that hardware could handle it atomically.

Which is it, please?



(Note: I tag this question both C and C++ because, when it comes to atomics, the two standards use almost identical language. For this reason, an expert in either language can answer as far as I know. If for some reason I am mistaken, then please remove the C tag and retain the C++.)



Reference: see also this question, for which my question is preliminary.







c++ c language-lawyer atomic definition






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 26 at 12:27









thbthb

8,75932356




8,75932356







  • 2





    Modern C and C++ have an atomic keyword, which is a type qualifier just like const. So I would assume atomic object means "an atomic-qualified object". That is, declared as (C11) _Atomic int blondie; with the _Atomic type qualifier.

    – Lundin
    Feb 26 at 12:35







  • 15





    @Lundin C++ does not have an atomic keyword.

    – eerorika
    Feb 26 at 12:36






  • 9





    @eerorika Well whatever, std::atomic<int> template fluff.

    – Lundin
    Feb 26 at 12:37






  • 1





    For C11, see: port70.net/~nsz/c/c11/n1570.html#6.2.5p20; port70.net/~nsz/c/c11/n1570.html#6.2.5p27; port70.net/~nsz/c/c11/n1570.html#6.2.6.1p9; port70.net/~nsz/c/c11/n1570.html#6.5.2.3p5; port70.net/~nsz/c/c11/n1570.html#6.5.2.4p2; port70.net/~nsz/c/c11/n1570.html#6.7.2.4; port70.net/~nsz/c/c11/n1570.html#6.7.3; Atomics <stdatomic.h>. And probably other places — there are lots of mentions of atomic in the standard linked to. C18 is very similar, though atomic figure in the changes.

    – Jonathan Leffler
    Feb 26 at 12:46







  • 1





    Atomic object is not necessarily an object of std::atomic type (at least in C++20). New std::atomic_­ref class template makes an object it refers to atomic. … for the lifetime of the atomic_­ref object, the object referenced by *ptr is an atomic object. Whether such wording is optimal is another question.

    – Language Lawyer
    Feb 26 at 13:20













  • 2





    Modern C and C++ have an atomic keyword, which is a type qualifier just like const. So I would assume atomic object means "an atomic-qualified object". That is, declared as (C11) _Atomic int blondie; with the _Atomic type qualifier.

    – Lundin
    Feb 26 at 12:35







  • 15





    @Lundin C++ does not have an atomic keyword.

    – eerorika
    Feb 26 at 12:36






  • 9





    @eerorika Well whatever, std::atomic<int> template fluff.

    – Lundin
    Feb 26 at 12:37






  • 1





    For C11, see: port70.net/~nsz/c/c11/n1570.html#6.2.5p20; port70.net/~nsz/c/c11/n1570.html#6.2.5p27; port70.net/~nsz/c/c11/n1570.html#6.2.6.1p9; port70.net/~nsz/c/c11/n1570.html#6.5.2.3p5; port70.net/~nsz/c/c11/n1570.html#6.5.2.4p2; port70.net/~nsz/c/c11/n1570.html#6.7.2.4; port70.net/~nsz/c/c11/n1570.html#6.7.3; Atomics <stdatomic.h>. And probably other places — there are lots of mentions of atomic in the standard linked to. C18 is very similar, though atomic figure in the changes.

    – Jonathan Leffler
    Feb 26 at 12:46







  • 1





    Atomic object is not necessarily an object of std::atomic type (at least in C++20). New std::atomic_­ref class template makes an object it refers to atomic. … for the lifetime of the atomic_­ref object, the object referenced by *ptr is an atomic object. Whether such wording is optimal is another question.

    – Language Lawyer
    Feb 26 at 13:20








2




2





Modern C and C++ have an atomic keyword, which is a type qualifier just like const. So I would assume atomic object means "an atomic-qualified object". That is, declared as (C11) _Atomic int blondie; with the _Atomic type qualifier.

– Lundin
Feb 26 at 12:35






Modern C and C++ have an atomic keyword, which is a type qualifier just like const. So I would assume atomic object means "an atomic-qualified object". That is, declared as (C11) _Atomic int blondie; with the _Atomic type qualifier.

– Lundin
Feb 26 at 12:35





15




15





@Lundin C++ does not have an atomic keyword.

– eerorika
Feb 26 at 12:36





@Lundin C++ does not have an atomic keyword.

– eerorika
Feb 26 at 12:36




9




9





@eerorika Well whatever, std::atomic<int> template fluff.

– Lundin
Feb 26 at 12:37





@eerorika Well whatever, std::atomic<int> template fluff.

– Lundin
Feb 26 at 12:37




1




1





For C11, see: port70.net/~nsz/c/c11/n1570.html#6.2.5p20; port70.net/~nsz/c/c11/n1570.html#6.2.5p27; port70.net/~nsz/c/c11/n1570.html#6.2.6.1p9; port70.net/~nsz/c/c11/n1570.html#6.5.2.3p5; port70.net/~nsz/c/c11/n1570.html#6.5.2.4p2; port70.net/~nsz/c/c11/n1570.html#6.7.2.4; port70.net/~nsz/c/c11/n1570.html#6.7.3; Atomics <stdatomic.h>. And probably other places — there are lots of mentions of atomic in the standard linked to. C18 is very similar, though atomic figure in the changes.

– Jonathan Leffler
Feb 26 at 12:46






For C11, see: port70.net/~nsz/c/c11/n1570.html#6.2.5p20; port70.net/~nsz/c/c11/n1570.html#6.2.5p27; port70.net/~nsz/c/c11/n1570.html#6.2.6.1p9; port70.net/~nsz/c/c11/n1570.html#6.5.2.3p5; port70.net/~nsz/c/c11/n1570.html#6.5.2.4p2; port70.net/~nsz/c/c11/n1570.html#6.7.2.4; port70.net/~nsz/c/c11/n1570.html#6.7.3; Atomics <stdatomic.h>. And probably other places — there are lots of mentions of atomic in the standard linked to. C18 is very similar, though atomic figure in the changes.

– Jonathan Leffler
Feb 26 at 12:46





1




1





Atomic object is not necessarily an object of std::atomic type (at least in C++20). New std::atomic_­ref class template makes an object it refers to atomic. … for the lifetime of the atomic_­ref object, the object referenced by *ptr is an atomic object. Whether such wording is optimal is another question.

– Language Lawyer
Feb 26 at 13:20






Atomic object is not necessarily an object of std::atomic type (at least in C++20). New std::atomic_­ref class template makes an object it refers to atomic. … for the lifetime of the atomic_­ref object, the object referenced by *ptr is an atomic object. Whether such wording is optimal is another question.

– Language Lawyer
Feb 26 at 13:20













3 Answers
3






active

oldest

votes


















7














The C++ standard imposes a set of rules on operations and effects of operations on atomic objects ([intro.races]). If all operations on an object satisfy those rules, then that object is atomic.




the phrase "atomic object" means "object of atomic type," does it not?




It is not worded so in the standard. But since the effect of operations is determined by the type of the object, this is not an unreasonable conclusion. Also correspondingly: Atomic type is a type whose instances are atomic objects.



The C++ standard library provides a set of types which are guaranteed to be atomic, as well as functions for those types which are guaranteed to be atomic operations ([atomics]).




properly aligned object small enough that hardware could handle it atomically.




C++ standard specifies nothing about alignment or size of atomic objects.



If an object/type is guaranteed to be atomic (see [atomics]), and if the hardware has such requirements for atomicity, then either the implementation of the language must guarantee that those requirements are met, or the implementation must employ locks to enforce atomicity.






share|improve this answer




















  • 2





    I can imagine an type that can change its atomicy during runtime. Not sure if thats a good thing to do, but usually they take very much care to not restrict generality in the standard when there is no need to. Maybe thats the reason there is no "atomic type" but only "atomic objects"

    – user463035818
    Feb 26 at 12:50







  • 1





    @user463035818 I suppose you could call such type conditionally atomic. There are atomic types, which are specified in [atomics] section.

    – eerorika
    Feb 26 at 12:53







  • 2





    @user463035818 This is probably why the member of std::atomic is named is_always_lock_free. Also note: "Atomic types are also allowed to be sometimes lock-free, e.g. if only aligned memory accesses are naturally atomic on a given architecture, misaligned objects of the same type have to use locks."

    – Max Langhof
    Feb 26 at 13:15






  • 1





    @MaxLanghof I have to admit, my comment was mainly to express my ignorance and confusion ;). I will have to do a lot more reading to understand what is going on. Hope I will have time to come back to this q/a later...

    – user463035818
    Feb 26 at 13:17











  • @user463035818: There are many situations where some particular accesses made to some objects will need to be ordered with respect to each other, but most operations won't. So far as I can tell, however, the Standard has no way of forcing the ordering of operations on "ordinary" objects.

    – supercat
    Feb 26 at 22:05


















17














In my view atomicity - strictly speaking - does not apply to types or objects, it applies to operations, i.e. you can say an operation is atomic or not.



By an "atomic object" we understand an object whose public interface exposes only atomic operations, i.e. all operations you can do with that object are atomic.



In C and C++ it may be that the concepts are defined the other way around: first define atomic objects and then define atomic operations in terms of atomic objects. It probably made sense for C and C++ to define it this way because the wording of the standard is primarily concerned with defining the language. However from a theoretical and abstract functionality perspective atomic operations are the main concern.



The C++ has the standard std::atomic<T> class template which fits the above descriptions.






share|improve this answer




















  • 4





    No, both standards explicitly and voluntarily talk about atomic objects. Atomic operations are those that deal with atomic objects.

    – Jens Gustedt
    Feb 26 at 13:08






  • 3





    @JensGustedt well, it probably made sense for C and C++ to define it this way because the wording of the standard is primarily concerned with defining the language. From a theory and abstract functionality perspective atomic operations are the main concern. Reworded the answer.

    – bolov
    Feb 26 at 13:28


















4














I can answer for C, but C++ is indeed intended to be in sync with C on these points.



Yes, when the C standard speaks of "atomic object" it means an object with an effective type that is atomic-qualified. But it also seems that this is not written down explicitly, so it would probably be a good idea to add that. I'll see to that.



Also, other than some people stated, there are no atomic operations in C without atomic objects. This is volontarily fixed like that, such that the atomicity of access to these objects can never be compromized.






share|improve this answer


















  • 3





    If you're going to propose changes to the C standard to clarify this, it would probably be a good idea to clarify the status of sig_atomic_t at the same time, since it has "atomic" in its name but, AFAIK, it is not an _Atomic-qualified type and offers only the weaker guarantee of its being well-defined to store to a volatile sig_atomic_t variable from a signal handler. (I'm not suggesting any substantive change here, only that the text should emphasize that sig_atomic_t is not _Atomic.)

    – zwol
    Feb 26 at 16:18







  • 2





    How should a programmer handle situations where it is necessary to e.g. ensure that an object which has been written via "ordinary" pointers will not have those accesses reordered by the compiler across some particular volatile write that will be performed later in the same thread?

    – supercat
    Feb 26 at 22:11










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54885590%2fdefinition-of-atomic-object%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









7














The C++ standard imposes a set of rules on operations and effects of operations on atomic objects ([intro.races]). If all operations on an object satisfy those rules, then that object is atomic.




the phrase "atomic object" means "object of atomic type," does it not?




It is not worded so in the standard. But since the effect of operations is determined by the type of the object, this is not an unreasonable conclusion. Also correspondingly: Atomic type is a type whose instances are atomic objects.



The C++ standard library provides a set of types which are guaranteed to be atomic, as well as functions for those types which are guaranteed to be atomic operations ([atomics]).




properly aligned object small enough that hardware could handle it atomically.




C++ standard specifies nothing about alignment or size of atomic objects.



If an object/type is guaranteed to be atomic (see [atomics]), and if the hardware has such requirements for atomicity, then either the implementation of the language must guarantee that those requirements are met, or the implementation must employ locks to enforce atomicity.






share|improve this answer




















  • 2





    I can imagine an type that can change its atomicy during runtime. Not sure if thats a good thing to do, but usually they take very much care to not restrict generality in the standard when there is no need to. Maybe thats the reason there is no "atomic type" but only "atomic objects"

    – user463035818
    Feb 26 at 12:50







  • 1





    @user463035818 I suppose you could call such type conditionally atomic. There are atomic types, which are specified in [atomics] section.

    – eerorika
    Feb 26 at 12:53







  • 2





    @user463035818 This is probably why the member of std::atomic is named is_always_lock_free. Also note: "Atomic types are also allowed to be sometimes lock-free, e.g. if only aligned memory accesses are naturally atomic on a given architecture, misaligned objects of the same type have to use locks."

    – Max Langhof
    Feb 26 at 13:15






  • 1





    @MaxLanghof I have to admit, my comment was mainly to express my ignorance and confusion ;). I will have to do a lot more reading to understand what is going on. Hope I will have time to come back to this q/a later...

    – user463035818
    Feb 26 at 13:17











  • @user463035818: There are many situations where some particular accesses made to some objects will need to be ordered with respect to each other, but most operations won't. So far as I can tell, however, the Standard has no way of forcing the ordering of operations on "ordinary" objects.

    – supercat
    Feb 26 at 22:05















7














The C++ standard imposes a set of rules on operations and effects of operations on atomic objects ([intro.races]). If all operations on an object satisfy those rules, then that object is atomic.




the phrase "atomic object" means "object of atomic type," does it not?




It is not worded so in the standard. But since the effect of operations is determined by the type of the object, this is not an unreasonable conclusion. Also correspondingly: Atomic type is a type whose instances are atomic objects.



The C++ standard library provides a set of types which are guaranteed to be atomic, as well as functions for those types which are guaranteed to be atomic operations ([atomics]).




properly aligned object small enough that hardware could handle it atomically.




C++ standard specifies nothing about alignment or size of atomic objects.



If an object/type is guaranteed to be atomic (see [atomics]), and if the hardware has such requirements for atomicity, then either the implementation of the language must guarantee that those requirements are met, or the implementation must employ locks to enforce atomicity.






share|improve this answer




















  • 2





    I can imagine an type that can change its atomicy during runtime. Not sure if thats a good thing to do, but usually they take very much care to not restrict generality in the standard when there is no need to. Maybe thats the reason there is no "atomic type" but only "atomic objects"

    – user463035818
    Feb 26 at 12:50







  • 1





    @user463035818 I suppose you could call such type conditionally atomic. There are atomic types, which are specified in [atomics] section.

    – eerorika
    Feb 26 at 12:53







  • 2





    @user463035818 This is probably why the member of std::atomic is named is_always_lock_free. Also note: "Atomic types are also allowed to be sometimes lock-free, e.g. if only aligned memory accesses are naturally atomic on a given architecture, misaligned objects of the same type have to use locks."

    – Max Langhof
    Feb 26 at 13:15






  • 1





    @MaxLanghof I have to admit, my comment was mainly to express my ignorance and confusion ;). I will have to do a lot more reading to understand what is going on. Hope I will have time to come back to this q/a later...

    – user463035818
    Feb 26 at 13:17











  • @user463035818: There are many situations where some particular accesses made to some objects will need to be ordered with respect to each other, but most operations won't. So far as I can tell, however, the Standard has no way of forcing the ordering of operations on "ordinary" objects.

    – supercat
    Feb 26 at 22:05













7












7








7







The C++ standard imposes a set of rules on operations and effects of operations on atomic objects ([intro.races]). If all operations on an object satisfy those rules, then that object is atomic.




the phrase "atomic object" means "object of atomic type," does it not?




It is not worded so in the standard. But since the effect of operations is determined by the type of the object, this is not an unreasonable conclusion. Also correspondingly: Atomic type is a type whose instances are atomic objects.



The C++ standard library provides a set of types which are guaranteed to be atomic, as well as functions for those types which are guaranteed to be atomic operations ([atomics]).




properly aligned object small enough that hardware could handle it atomically.




C++ standard specifies nothing about alignment or size of atomic objects.



If an object/type is guaranteed to be atomic (see [atomics]), and if the hardware has such requirements for atomicity, then either the implementation of the language must guarantee that those requirements are met, or the implementation must employ locks to enforce atomicity.






share|improve this answer















The C++ standard imposes a set of rules on operations and effects of operations on atomic objects ([intro.races]). If all operations on an object satisfy those rules, then that object is atomic.




the phrase "atomic object" means "object of atomic type," does it not?




It is not worded so in the standard. But since the effect of operations is determined by the type of the object, this is not an unreasonable conclusion. Also correspondingly: Atomic type is a type whose instances are atomic objects.



The C++ standard library provides a set of types which are guaranteed to be atomic, as well as functions for those types which are guaranteed to be atomic operations ([atomics]).




properly aligned object small enough that hardware could handle it atomically.




C++ standard specifies nothing about alignment or size of atomic objects.



If an object/type is guaranteed to be atomic (see [atomics]), and if the hardware has such requirements for atomicity, then either the implementation of the language must guarantee that those requirements are met, or the implementation must employ locks to enforce atomicity.







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 26 at 15:54

























answered Feb 26 at 12:41









eerorikaeerorika

87.3k663134




87.3k663134







  • 2





    I can imagine an type that can change its atomicy during runtime. Not sure if thats a good thing to do, but usually they take very much care to not restrict generality in the standard when there is no need to. Maybe thats the reason there is no "atomic type" but only "atomic objects"

    – user463035818
    Feb 26 at 12:50







  • 1





    @user463035818 I suppose you could call such type conditionally atomic. There are atomic types, which are specified in [atomics] section.

    – eerorika
    Feb 26 at 12:53







  • 2





    @user463035818 This is probably why the member of std::atomic is named is_always_lock_free. Also note: "Atomic types are also allowed to be sometimes lock-free, e.g. if only aligned memory accesses are naturally atomic on a given architecture, misaligned objects of the same type have to use locks."

    – Max Langhof
    Feb 26 at 13:15






  • 1





    @MaxLanghof I have to admit, my comment was mainly to express my ignorance and confusion ;). I will have to do a lot more reading to understand what is going on. Hope I will have time to come back to this q/a later...

    – user463035818
    Feb 26 at 13:17











  • @user463035818: There are many situations where some particular accesses made to some objects will need to be ordered with respect to each other, but most operations won't. So far as I can tell, however, the Standard has no way of forcing the ordering of operations on "ordinary" objects.

    – supercat
    Feb 26 at 22:05












  • 2





    I can imagine an type that can change its atomicy during runtime. Not sure if thats a good thing to do, but usually they take very much care to not restrict generality in the standard when there is no need to. Maybe thats the reason there is no "atomic type" but only "atomic objects"

    – user463035818
    Feb 26 at 12:50







  • 1





    @user463035818 I suppose you could call such type conditionally atomic. There are atomic types, which are specified in [atomics] section.

    – eerorika
    Feb 26 at 12:53







  • 2





    @user463035818 This is probably why the member of std::atomic is named is_always_lock_free. Also note: "Atomic types are also allowed to be sometimes lock-free, e.g. if only aligned memory accesses are naturally atomic on a given architecture, misaligned objects of the same type have to use locks."

    – Max Langhof
    Feb 26 at 13:15






  • 1





    @MaxLanghof I have to admit, my comment was mainly to express my ignorance and confusion ;). I will have to do a lot more reading to understand what is going on. Hope I will have time to come back to this q/a later...

    – user463035818
    Feb 26 at 13:17











  • @user463035818: There are many situations where some particular accesses made to some objects will need to be ordered with respect to each other, but most operations won't. So far as I can tell, however, the Standard has no way of forcing the ordering of operations on "ordinary" objects.

    – supercat
    Feb 26 at 22:05







2




2





I can imagine an type that can change its atomicy during runtime. Not sure if thats a good thing to do, but usually they take very much care to not restrict generality in the standard when there is no need to. Maybe thats the reason there is no "atomic type" but only "atomic objects"

– user463035818
Feb 26 at 12:50






I can imagine an type that can change its atomicy during runtime. Not sure if thats a good thing to do, but usually they take very much care to not restrict generality in the standard when there is no need to. Maybe thats the reason there is no "atomic type" but only "atomic objects"

– user463035818
Feb 26 at 12:50





1




1





@user463035818 I suppose you could call such type conditionally atomic. There are atomic types, which are specified in [atomics] section.

– eerorika
Feb 26 at 12:53






@user463035818 I suppose you could call such type conditionally atomic. There are atomic types, which are specified in [atomics] section.

– eerorika
Feb 26 at 12:53





2




2





@user463035818 This is probably why the member of std::atomic is named is_always_lock_free. Also note: "Atomic types are also allowed to be sometimes lock-free, e.g. if only aligned memory accesses are naturally atomic on a given architecture, misaligned objects of the same type have to use locks."

– Max Langhof
Feb 26 at 13:15





@user463035818 This is probably why the member of std::atomic is named is_always_lock_free. Also note: "Atomic types are also allowed to be sometimes lock-free, e.g. if only aligned memory accesses are naturally atomic on a given architecture, misaligned objects of the same type have to use locks."

– Max Langhof
Feb 26 at 13:15




1




1





@MaxLanghof I have to admit, my comment was mainly to express my ignorance and confusion ;). I will have to do a lot more reading to understand what is going on. Hope I will have time to come back to this q/a later...

– user463035818
Feb 26 at 13:17





@MaxLanghof I have to admit, my comment was mainly to express my ignorance and confusion ;). I will have to do a lot more reading to understand what is going on. Hope I will have time to come back to this q/a later...

– user463035818
Feb 26 at 13:17













@user463035818: There are many situations where some particular accesses made to some objects will need to be ordered with respect to each other, but most operations won't. So far as I can tell, however, the Standard has no way of forcing the ordering of operations on "ordinary" objects.

– supercat
Feb 26 at 22:05





@user463035818: There are many situations where some particular accesses made to some objects will need to be ordered with respect to each other, but most operations won't. So far as I can tell, however, the Standard has no way of forcing the ordering of operations on "ordinary" objects.

– supercat
Feb 26 at 22:05













17














In my view atomicity - strictly speaking - does not apply to types or objects, it applies to operations, i.e. you can say an operation is atomic or not.



By an "atomic object" we understand an object whose public interface exposes only atomic operations, i.e. all operations you can do with that object are atomic.



In C and C++ it may be that the concepts are defined the other way around: first define atomic objects and then define atomic operations in terms of atomic objects. It probably made sense for C and C++ to define it this way because the wording of the standard is primarily concerned with defining the language. However from a theoretical and abstract functionality perspective atomic operations are the main concern.



The C++ has the standard std::atomic<T> class template which fits the above descriptions.






share|improve this answer




















  • 4





    No, both standards explicitly and voluntarily talk about atomic objects. Atomic operations are those that deal with atomic objects.

    – Jens Gustedt
    Feb 26 at 13:08






  • 3





    @JensGustedt well, it probably made sense for C and C++ to define it this way because the wording of the standard is primarily concerned with defining the language. From a theory and abstract functionality perspective atomic operations are the main concern. Reworded the answer.

    – bolov
    Feb 26 at 13:28















17














In my view atomicity - strictly speaking - does not apply to types or objects, it applies to operations, i.e. you can say an operation is atomic or not.



By an "atomic object" we understand an object whose public interface exposes only atomic operations, i.e. all operations you can do with that object are atomic.



In C and C++ it may be that the concepts are defined the other way around: first define atomic objects and then define atomic operations in terms of atomic objects. It probably made sense for C and C++ to define it this way because the wording of the standard is primarily concerned with defining the language. However from a theoretical and abstract functionality perspective atomic operations are the main concern.



The C++ has the standard std::atomic<T> class template which fits the above descriptions.






share|improve this answer




















  • 4





    No, both standards explicitly and voluntarily talk about atomic objects. Atomic operations are those that deal with atomic objects.

    – Jens Gustedt
    Feb 26 at 13:08






  • 3





    @JensGustedt well, it probably made sense for C and C++ to define it this way because the wording of the standard is primarily concerned with defining the language. From a theory and abstract functionality perspective atomic operations are the main concern. Reworded the answer.

    – bolov
    Feb 26 at 13:28













17












17








17







In my view atomicity - strictly speaking - does not apply to types or objects, it applies to operations, i.e. you can say an operation is atomic or not.



By an "atomic object" we understand an object whose public interface exposes only atomic operations, i.e. all operations you can do with that object are atomic.



In C and C++ it may be that the concepts are defined the other way around: first define atomic objects and then define atomic operations in terms of atomic objects. It probably made sense for C and C++ to define it this way because the wording of the standard is primarily concerned with defining the language. However from a theoretical and abstract functionality perspective atomic operations are the main concern.



The C++ has the standard std::atomic<T> class template which fits the above descriptions.






share|improve this answer















In my view atomicity - strictly speaking - does not apply to types or objects, it applies to operations, i.e. you can say an operation is atomic or not.



By an "atomic object" we understand an object whose public interface exposes only atomic operations, i.e. all operations you can do with that object are atomic.



In C and C++ it may be that the concepts are defined the other way around: first define atomic objects and then define atomic operations in terms of atomic objects. It probably made sense for C and C++ to define it this way because the wording of the standard is primarily concerned with defining the language. However from a theoretical and abstract functionality perspective atomic operations are the main concern.



The C++ has the standard std::atomic<T> class template which fits the above descriptions.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 14 at 20:22

























answered Feb 26 at 12:38









bolovbolov

32.7k676140




32.7k676140







  • 4





    No, both standards explicitly and voluntarily talk about atomic objects. Atomic operations are those that deal with atomic objects.

    – Jens Gustedt
    Feb 26 at 13:08






  • 3





    @JensGustedt well, it probably made sense for C and C++ to define it this way because the wording of the standard is primarily concerned with defining the language. From a theory and abstract functionality perspective atomic operations are the main concern. Reworded the answer.

    – bolov
    Feb 26 at 13:28












  • 4





    No, both standards explicitly and voluntarily talk about atomic objects. Atomic operations are those that deal with atomic objects.

    – Jens Gustedt
    Feb 26 at 13:08






  • 3





    @JensGustedt well, it probably made sense for C and C++ to define it this way because the wording of the standard is primarily concerned with defining the language. From a theory and abstract functionality perspective atomic operations are the main concern. Reworded the answer.

    – bolov
    Feb 26 at 13:28







4




4





No, both standards explicitly and voluntarily talk about atomic objects. Atomic operations are those that deal with atomic objects.

– Jens Gustedt
Feb 26 at 13:08





No, both standards explicitly and voluntarily talk about atomic objects. Atomic operations are those that deal with atomic objects.

– Jens Gustedt
Feb 26 at 13:08




3




3





@JensGustedt well, it probably made sense for C and C++ to define it this way because the wording of the standard is primarily concerned with defining the language. From a theory and abstract functionality perspective atomic operations are the main concern. Reworded the answer.

– bolov
Feb 26 at 13:28





@JensGustedt well, it probably made sense for C and C++ to define it this way because the wording of the standard is primarily concerned with defining the language. From a theory and abstract functionality perspective atomic operations are the main concern. Reworded the answer.

– bolov
Feb 26 at 13:28











4














I can answer for C, but C++ is indeed intended to be in sync with C on these points.



Yes, when the C standard speaks of "atomic object" it means an object with an effective type that is atomic-qualified. But it also seems that this is not written down explicitly, so it would probably be a good idea to add that. I'll see to that.



Also, other than some people stated, there are no atomic operations in C without atomic objects. This is volontarily fixed like that, such that the atomicity of access to these objects can never be compromized.






share|improve this answer


















  • 3





    If you're going to propose changes to the C standard to clarify this, it would probably be a good idea to clarify the status of sig_atomic_t at the same time, since it has "atomic" in its name but, AFAIK, it is not an _Atomic-qualified type and offers only the weaker guarantee of its being well-defined to store to a volatile sig_atomic_t variable from a signal handler. (I'm not suggesting any substantive change here, only that the text should emphasize that sig_atomic_t is not _Atomic.)

    – zwol
    Feb 26 at 16:18







  • 2





    How should a programmer handle situations where it is necessary to e.g. ensure that an object which has been written via "ordinary" pointers will not have those accesses reordered by the compiler across some particular volatile write that will be performed later in the same thread?

    – supercat
    Feb 26 at 22:11















4














I can answer for C, but C++ is indeed intended to be in sync with C on these points.



Yes, when the C standard speaks of "atomic object" it means an object with an effective type that is atomic-qualified. But it also seems that this is not written down explicitly, so it would probably be a good idea to add that. I'll see to that.



Also, other than some people stated, there are no atomic operations in C without atomic objects. This is volontarily fixed like that, such that the atomicity of access to these objects can never be compromized.






share|improve this answer


















  • 3





    If you're going to propose changes to the C standard to clarify this, it would probably be a good idea to clarify the status of sig_atomic_t at the same time, since it has "atomic" in its name but, AFAIK, it is not an _Atomic-qualified type and offers only the weaker guarantee of its being well-defined to store to a volatile sig_atomic_t variable from a signal handler. (I'm not suggesting any substantive change here, only that the text should emphasize that sig_atomic_t is not _Atomic.)

    – zwol
    Feb 26 at 16:18







  • 2





    How should a programmer handle situations where it is necessary to e.g. ensure that an object which has been written via "ordinary" pointers will not have those accesses reordered by the compiler across some particular volatile write that will be performed later in the same thread?

    – supercat
    Feb 26 at 22:11













4












4








4







I can answer for C, but C++ is indeed intended to be in sync with C on these points.



Yes, when the C standard speaks of "atomic object" it means an object with an effective type that is atomic-qualified. But it also seems that this is not written down explicitly, so it would probably be a good idea to add that. I'll see to that.



Also, other than some people stated, there are no atomic operations in C without atomic objects. This is volontarily fixed like that, such that the atomicity of access to these objects can never be compromized.






share|improve this answer













I can answer for C, but C++ is indeed intended to be in sync with C on these points.



Yes, when the C standard speaks of "atomic object" it means an object with an effective type that is atomic-qualified. But it also seems that this is not written down explicitly, so it would probably be a good idea to add that. I'll see to that.



Also, other than some people stated, there are no atomic operations in C without atomic objects. This is volontarily fixed like that, such that the atomicity of access to these objects can never be compromized.







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 26 at 13:19









Jens GustedtJens Gustedt

65.9k275144




65.9k275144







  • 3





    If you're going to propose changes to the C standard to clarify this, it would probably be a good idea to clarify the status of sig_atomic_t at the same time, since it has "atomic" in its name but, AFAIK, it is not an _Atomic-qualified type and offers only the weaker guarantee of its being well-defined to store to a volatile sig_atomic_t variable from a signal handler. (I'm not suggesting any substantive change here, only that the text should emphasize that sig_atomic_t is not _Atomic.)

    – zwol
    Feb 26 at 16:18







  • 2





    How should a programmer handle situations where it is necessary to e.g. ensure that an object which has been written via "ordinary" pointers will not have those accesses reordered by the compiler across some particular volatile write that will be performed later in the same thread?

    – supercat
    Feb 26 at 22:11












  • 3





    If you're going to propose changes to the C standard to clarify this, it would probably be a good idea to clarify the status of sig_atomic_t at the same time, since it has "atomic" in its name but, AFAIK, it is not an _Atomic-qualified type and offers only the weaker guarantee of its being well-defined to store to a volatile sig_atomic_t variable from a signal handler. (I'm not suggesting any substantive change here, only that the text should emphasize that sig_atomic_t is not _Atomic.)

    – zwol
    Feb 26 at 16:18







  • 2





    How should a programmer handle situations where it is necessary to e.g. ensure that an object which has been written via "ordinary" pointers will not have those accesses reordered by the compiler across some particular volatile write that will be performed later in the same thread?

    – supercat
    Feb 26 at 22:11







3




3





If you're going to propose changes to the C standard to clarify this, it would probably be a good idea to clarify the status of sig_atomic_t at the same time, since it has "atomic" in its name but, AFAIK, it is not an _Atomic-qualified type and offers only the weaker guarantee of its being well-defined to store to a volatile sig_atomic_t variable from a signal handler. (I'm not suggesting any substantive change here, only that the text should emphasize that sig_atomic_t is not _Atomic.)

– zwol
Feb 26 at 16:18






If you're going to propose changes to the C standard to clarify this, it would probably be a good idea to clarify the status of sig_atomic_t at the same time, since it has "atomic" in its name but, AFAIK, it is not an _Atomic-qualified type and offers only the weaker guarantee of its being well-defined to store to a volatile sig_atomic_t variable from a signal handler. (I'm not suggesting any substantive change here, only that the text should emphasize that sig_atomic_t is not _Atomic.)

– zwol
Feb 26 at 16:18





2




2





How should a programmer handle situations where it is necessary to e.g. ensure that an object which has been written via "ordinary" pointers will not have those accesses reordered by the compiler across some particular volatile write that will be performed later in the same thread?

– supercat
Feb 26 at 22:11





How should a programmer handle situations where it is necessary to e.g. ensure that an object which has been written via "ordinary" pointers will not have those accesses reordered by the compiler across some particular volatile write that will be performed later in the same thread?

– supercat
Feb 26 at 22:11

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54885590%2fdefinition-of-atomic-object%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?