Definition of “atomic object”What exact rules in the C++ memory model prevent reordering before acquire...
Does Skippy chunky peanut butter contain trans fat?
What senses are available to a corpse subjected to a Speak with Dead spell?
How vim overwrites readonly mode?
Which RAF squadrons and aircraft types took part in the bombing of Berlin on the 25th of August 1940?
Cat is tipping over bed-side lamps during the night
How to access internet and run apt-get through a middle server?
Why does 0.-5 evaluate to -5?
What's the oldest plausible frozen specimen for a Jurassic Park style story-line?
Do authors have to be politically correct in article-writing?
Am I correct in stating that the study of topology is purely theoretical?
In harmony: key or the flow?
Can we "borrow" our answers to populate our own websites?
Calculate of total length of edges in Voronoi diagram
Why avoid shared user accounts?
Is Screenshot Time-tracking Common?
Why is a temp table a more efficient solution to the Halloween Problem than an eager spool?
What can I do to encourage my players to use their consumables?
Book where a space ship journeys to the center of the galaxy to find all the stars had gone supernova
Why maximum length of IP, TCP, UDP packet is not suit?
Translation needed for 130 years old church document
Has any human ever had the choice to leave Earth permanently?
Does it take energy to move something in a circle?
Existence of Riemann surface, holomorphic maps
Why do we have to make "peinlich" start with a capital letter and also end with -s in this sentence?
Definition of “atomic object”
What exact rules in the C++ memory model prevent reordering before acquire operations?The Definitive C++ Book Guide and ListWhat's the difference between the atomic and nonatomic attributes?What is the difference between a definition and a declaration?typedef struct vs struct definitionsPurpose of Unions in C and C++Why is f(i = -1, i = -1) undefined behavior?Why should I use a pointer rather than the object itself?Is a relaxed atomic counter safe?What's the meaning of “reserved for any use”?Is the standard's ODR example correct?
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
add a comment |
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
Modern C and C++ have an atomic keyword, which is a type qualifier just likeconst. So I would assume atomic object means "an atomic-qualified object". That is, declared as (C11)_Atomic int blondie;with the_Atomictype qualifier.
– Lundin
1 hour ago
7
@Lundin C++ does not have an atomic keyword.
– eerorika
1 hour ago
2
@eerorika Well whatever,std::atomic<int>template fluff.
– Lundin
1 hour ago
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 ofatomicin the standard linked to. C18 is very similar, though atomic figure in the changes.
– Jonathan Leffler
56 mins ago
1
Atomic object is not necessarily an object ofstd::atomictype (at least in C++20). Newstd::atomic_refclass template makes an object it refers to atomic. … for the lifetime of theatomic_refobject, the object referenced by*ptris an atomic object. Whether such wording is optimal is another question.
– Language Lawyer
22 mins ago
add a comment |
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
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
c++ c language-lawyer atomic definition
asked 1 hour ago
thbthb
8,14232149
8,14232149
Modern C and C++ have an atomic keyword, which is a type qualifier just likeconst. So I would assume atomic object means "an atomic-qualified object". That is, declared as (C11)_Atomic int blondie;with the_Atomictype qualifier.
– Lundin
1 hour ago
7
@Lundin C++ does not have an atomic keyword.
– eerorika
1 hour ago
2
@eerorika Well whatever,std::atomic<int>template fluff.
– Lundin
1 hour ago
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 ofatomicin the standard linked to. C18 is very similar, though atomic figure in the changes.
– Jonathan Leffler
56 mins ago
1
Atomic object is not necessarily an object ofstd::atomictype (at least in C++20). Newstd::atomic_refclass template makes an object it refers to atomic. … for the lifetime of theatomic_refobject, the object referenced by*ptris an atomic object. Whether such wording is optimal is another question.
– Language Lawyer
22 mins ago
add a comment |
Modern C and C++ have an atomic keyword, which is a type qualifier just likeconst. So I would assume atomic object means "an atomic-qualified object". That is, declared as (C11)_Atomic int blondie;with the_Atomictype qualifier.
– Lundin
1 hour ago
7
@Lundin C++ does not have an atomic keyword.
– eerorika
1 hour ago
2
@eerorika Well whatever,std::atomic<int>template fluff.
– Lundin
1 hour ago
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 ofatomicin the standard linked to. C18 is very similar, though atomic figure in the changes.
– Jonathan Leffler
56 mins ago
1
Atomic object is not necessarily an object ofstd::atomictype (at least in C++20). Newstd::atomic_refclass template makes an object it refers to atomic. … for the lifetime of theatomic_refobject, the object referenced by*ptris an atomic object. Whether such wording is optimal is another question.
– Language Lawyer
22 mins ago
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
1 hour ago
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
1 hour ago
7
7
@Lundin C++ does not have an atomic keyword.
– eerorika
1 hour ago
@Lundin C++ does not have an atomic keyword.
– eerorika
1 hour ago
2
2
@eerorika Well whatever,
std::atomic<int> template fluff.– Lundin
1 hour ago
@eerorika Well whatever,
std::atomic<int> template fluff.– Lundin
1 hour ago
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
56 mins ago
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
56 mins ago
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
22 mins ago
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
22 mins ago
add a comment |
3 Answers
3
active
oldest
votes
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.
However when you say "atomic object" you actually mean 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 they are defined the other way around: first define atomic objects and then define atomic operations in terms of atomic objects.
The C++ has the standard std::atomic<T> class template which fits the above descriptions.
1
No, both standards explicitly and voluntarily talk about atomic objects. Atomic operations are those that deal with atomic objects.
– Jens Gustedt
34 mins ago
@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
14 mins ago
add a comment |
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 specified 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.
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
52 mins ago
@user463035818 I suppose you could call such type conditionally atomic. There are atomic types, which are specified in [atomics] section.
– eerorika
49 mins ago
1
@user463035818 This is probably why the member ofstd::atomicis namedis_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
27 mins ago
@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
25 mins ago
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
However when you say "atomic object" you actually mean 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 they are defined the other way around: first define atomic objects and then define atomic operations in terms of atomic objects.
The C++ has the standard std::atomic<T> class template which fits the above descriptions.
1
No, both standards explicitly and voluntarily talk about atomic objects. Atomic operations are those that deal with atomic objects.
– Jens Gustedt
34 mins ago
@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
14 mins ago
add a comment |
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.
However when you say "atomic object" you actually mean 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 they are defined the other way around: first define atomic objects and then define atomic operations in terms of atomic objects.
The C++ has the standard std::atomic<T> class template which fits the above descriptions.
1
No, both standards explicitly and voluntarily talk about atomic objects. Atomic operations are those that deal with atomic objects.
– Jens Gustedt
34 mins ago
@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
14 mins ago
add a comment |
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.
However when you say "atomic object" you actually mean 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 they are defined the other way around: first define atomic objects and then define atomic operations in terms of atomic objects.
The C++ has the standard std::atomic<T> class template which fits the above descriptions.
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.
However when you say "atomic object" you actually mean 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 they are defined the other way around: first define atomic objects and then define atomic operations in terms of atomic objects.
The C++ has the standard std::atomic<T> class template which fits the above descriptions.
edited 15 mins ago
answered 1 hour ago
bolovbolov
31.5k671131
31.5k671131
1
No, both standards explicitly and voluntarily talk about atomic objects. Atomic operations are those that deal with atomic objects.
– Jens Gustedt
34 mins ago
@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
14 mins ago
add a comment |
1
No, both standards explicitly and voluntarily talk about atomic objects. Atomic operations are those that deal with atomic objects.
– Jens Gustedt
34 mins ago
@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
14 mins ago
1
1
No, both standards explicitly and voluntarily talk about atomic objects. Atomic operations are those that deal with atomic objects.
– Jens Gustedt
34 mins ago
No, both standards explicitly and voluntarily talk about atomic objects. Atomic operations are those that deal with atomic objects.
– Jens Gustedt
34 mins ago
@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
14 mins ago
@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
14 mins ago
add a comment |
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 specified 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.
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
52 mins ago
@user463035818 I suppose you could call such type conditionally atomic. There are atomic types, which are specified in [atomics] section.
– eerorika
49 mins ago
1
@user463035818 This is probably why the member ofstd::atomicis namedis_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
27 mins ago
@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
25 mins ago
add a comment |
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 specified 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.
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
52 mins ago
@user463035818 I suppose you could call such type conditionally atomic. There are atomic types, which are specified in [atomics] section.
– eerorika
49 mins ago
1
@user463035818 This is probably why the member ofstd::atomicis namedis_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
27 mins ago
@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
25 mins ago
add a comment |
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 specified 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.
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 specified 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.
edited 31 mins ago
answered 1 hour ago
eerorikaeerorika
83.4k662128
83.4k662128
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
52 mins ago
@user463035818 I suppose you could call such type conditionally atomic. There are atomic types, which are specified in [atomics] section.
– eerorika
49 mins ago
1
@user463035818 This is probably why the member ofstd::atomicis namedis_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
27 mins ago
@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
25 mins ago
add a comment |
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
52 mins ago
@user463035818 I suppose you could call such type conditionally atomic. There are atomic types, which are specified in [atomics] section.
– eerorika
49 mins ago
1
@user463035818 This is probably why the member ofstd::atomicis namedis_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
27 mins ago
@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
25 mins ago
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
52 mins ago
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
52 mins ago
@user463035818 I suppose you could call such type conditionally atomic. There are atomic types, which are specified in [atomics] section.
– eerorika
49 mins ago
@user463035818 I suppose you could call such type conditionally atomic. There are atomic types, which are specified in [atomics] section.
– eerorika
49 mins ago
1
1
@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
27 mins ago
@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
27 mins ago
@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
25 mins ago
@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
25 mins ago
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered 23 mins ago
Jens GustedtJens Gustedt
65.3k272141
65.3k272141
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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_Atomictype qualifier.– Lundin
1 hour ago
7
@Lundin C++ does not have an atomic keyword.
– eerorika
1 hour ago
2
@eerorika Well whatever,
std::atomic<int>template fluff.– Lundin
1 hour ago
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 ofatomicin the standard linked to. C18 is very similar, though atomic figure in the changes.– Jonathan Leffler
56 mins ago
1
Atomic object is not necessarily an object of
std::atomictype (at least in C++20). Newstd::atomic_refclass template makes an object it refers to atomic. … for the lifetime of theatomic_refobject, the object referenced by*ptris an atomic object. Whether such wording is optimal is another question.– Language Lawyer
22 mins ago