Is it legal to call shared_future::get() multiple times on the same instance in the same thread?Purpose of Unions in C and C++Accessing inactive union member and undefined behavior?boost::thread and starting or not starting large numbers of threads at the same timeWhy is f(i = -1, i = -1) undefined behavior?Call a function from another threadboost::thread and std::thread compatibility issues?How to implement classic sorting algorithms in modern C++?Is the Visual C++ implementation of std::async using a thread pool legalIs it legal to call delete on a null pointer of an incomplete type?May a call to std::lock pass a resource that is already locked by the calling thread?
Milky way is orbiting around?
What is the maximum amount of diamond in one Minecraft game?
Are "confidant" and "confident" homophones?
Advice for making/keeping shredded chicken moist?
What is the fundamental difference between catching whales and hunting other animals?
Did Stalin kill all Soviet officers involved in the Winter War?
In the Seventh Seal why does Death let the chess game happen?
What units are kpts?
How can one synthesise a conjugated alkyne chain?
What is exact meaning of “ich wäre gern”?
Does a multiclassed wizard start with a spellbook?
Chess problem: Make a crossword in 3 moves
Bypass with wrong cvv of debit card and getting OTP
How to improve the size of cells in this table?
How did שְׁלֹמֹה (shlomo) become Solomon?
Platform Event Design when Subscribers are Apex Triggers
What do you call the angle of the direction of an airplane?
Park the computer
Is it possible to spoof an IP address to an exact number?
Contributing to a candidate as a Foreign National US Resident?
Why did C++11 make std::string::data() add a null terminating character?
Why did the "Orks" never develop better firearms than Firelances and Handcannons?
Minimizing medical costs with HSA
PhD: When to quit and move on?
Is it legal to call shared_future::get() multiple times on the same instance in the same thread?
Purpose of Unions in C and C++Accessing inactive union member and undefined behavior?boost::thread and starting or not starting large numbers of threads at the same timeWhy is f(i = -1, i = -1) undefined behavior?Call a function from another threadboost::thread and std::thread compatibility issues?How to implement classic sorting algorithms in modern C++?Is the Visual C++ implementation of std::async using a thread pool legalIs it legal to call delete on a null pointer of an incomplete type?May a call to std::lock pass a resource that is already locked by the calling thread?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I can find neither direct confirmation nor refutation on the matter. All answers seem to address the "access from multiple threads" aspect, rather than repetitive access itself.
Does the standard define the behavior for std::shared_future
? What about boost::shared_future
?
c++ boost future
add a comment |
I can find neither direct confirmation nor refutation on the matter. All answers seem to address the "access from multiple threads" aspect, rather than repetitive access itself.
Does the standard define the behavior for std::shared_future
? What about boost::shared_future
?
c++ boost future
add a comment |
I can find neither direct confirmation nor refutation on the matter. All answers seem to address the "access from multiple threads" aspect, rather than repetitive access itself.
Does the standard define the behavior for std::shared_future
? What about boost::shared_future
?
c++ boost future
I can find neither direct confirmation nor refutation on the matter. All answers seem to address the "access from multiple threads" aspect, rather than repetitive access itself.
Does the standard define the behavior for std::shared_future
? What about boost::shared_future
?
c++ boost future
c++ boost future
asked Jun 25 at 14:15
vinesvines
4,4681 gold badge20 silver badges44 bronze badges
4,4681 gold badge20 silver badges44 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Per cppreference in std::shared_future<T>::valid
Unlike std::future, std::shared_future's shared state is not invalidated when get() is called.
Which makes sense. If it wasn't the case then you couldn't have multiple threads be able to call get
. We can further back this up by looking at the standard. In [futures.unique.future]/15 they explicitly state get
only works once with
releases any shared state ([futures.state]).
while in [futures.shared.future]/18 it states no such thing so the state is still valid after get
is called.
boost::shared_future
has the same behavior. Per the reference get
has no text stating it invalidates the shared state on a call to get
so you can call it multiple times.
By the way, a curious observation on boost::futures. The link in the answer leads to docs onboost::fibers::shared_future
, which (again!) seem to differ in behavior from boost::shared_future (which is defined in 'boost::thread').
– vines
Jun 25 at 15:11
@vines Oh wow. Didn't notice that. I'll fix the answer.
– NathanOliver
Jun 25 at 15:15
Ah, found! It is stated in the first example on shared_future:use3( ftr.get() ); // second use is defined
– vines
Jun 25 at 16:23
add a comment |
AFAIK this is legal. std::shared_future<T>::get()
says:
The behavior is undefined if
valid()
isfalse
before the call to this
function.
Going to std::shared_future<T>::valid()
it says:
Checks if the future refers to a shared state.
...
Unlike
std::future
,std::shared_future
's shared state is not
invalidated whenget()
is called.
Which would make multiple get()
calls from the same thread and on the same instance valid.
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%2f56756112%2fis-it-legal-to-call-shared-futureget-multiple-times-on-the-same-instance-in%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Per cppreference in std::shared_future<T>::valid
Unlike std::future, std::shared_future's shared state is not invalidated when get() is called.
Which makes sense. If it wasn't the case then you couldn't have multiple threads be able to call get
. We can further back this up by looking at the standard. In [futures.unique.future]/15 they explicitly state get
only works once with
releases any shared state ([futures.state]).
while in [futures.shared.future]/18 it states no such thing so the state is still valid after get
is called.
boost::shared_future
has the same behavior. Per the reference get
has no text stating it invalidates the shared state on a call to get
so you can call it multiple times.
By the way, a curious observation on boost::futures. The link in the answer leads to docs onboost::fibers::shared_future
, which (again!) seem to differ in behavior from boost::shared_future (which is defined in 'boost::thread').
– vines
Jun 25 at 15:11
@vines Oh wow. Didn't notice that. I'll fix the answer.
– NathanOliver
Jun 25 at 15:15
Ah, found! It is stated in the first example on shared_future:use3( ftr.get() ); // second use is defined
– vines
Jun 25 at 16:23
add a comment |
Per cppreference in std::shared_future<T>::valid
Unlike std::future, std::shared_future's shared state is not invalidated when get() is called.
Which makes sense. If it wasn't the case then you couldn't have multiple threads be able to call get
. We can further back this up by looking at the standard. In [futures.unique.future]/15 they explicitly state get
only works once with
releases any shared state ([futures.state]).
while in [futures.shared.future]/18 it states no such thing so the state is still valid after get
is called.
boost::shared_future
has the same behavior. Per the reference get
has no text stating it invalidates the shared state on a call to get
so you can call it multiple times.
By the way, a curious observation on boost::futures. The link in the answer leads to docs onboost::fibers::shared_future
, which (again!) seem to differ in behavior from boost::shared_future (which is defined in 'boost::thread').
– vines
Jun 25 at 15:11
@vines Oh wow. Didn't notice that. I'll fix the answer.
– NathanOliver
Jun 25 at 15:15
Ah, found! It is stated in the first example on shared_future:use3( ftr.get() ); // second use is defined
– vines
Jun 25 at 16:23
add a comment |
Per cppreference in std::shared_future<T>::valid
Unlike std::future, std::shared_future's shared state is not invalidated when get() is called.
Which makes sense. If it wasn't the case then you couldn't have multiple threads be able to call get
. We can further back this up by looking at the standard. In [futures.unique.future]/15 they explicitly state get
only works once with
releases any shared state ([futures.state]).
while in [futures.shared.future]/18 it states no such thing so the state is still valid after get
is called.
boost::shared_future
has the same behavior. Per the reference get
has no text stating it invalidates the shared state on a call to get
so you can call it multiple times.
Per cppreference in std::shared_future<T>::valid
Unlike std::future, std::shared_future's shared state is not invalidated when get() is called.
Which makes sense. If it wasn't the case then you couldn't have multiple threads be able to call get
. We can further back this up by looking at the standard. In [futures.unique.future]/15 they explicitly state get
only works once with
releases any shared state ([futures.state]).
while in [futures.shared.future]/18 it states no such thing so the state is still valid after get
is called.
boost::shared_future
has the same behavior. Per the reference get
has no text stating it invalidates the shared state on a call to get
so you can call it multiple times.
edited Jun 25 at 15:16
answered Jun 25 at 14:22
NathanOliverNathanOliver
107k19 gold badges159 silver badges236 bronze badges
107k19 gold badges159 silver badges236 bronze badges
By the way, a curious observation on boost::futures. The link in the answer leads to docs onboost::fibers::shared_future
, which (again!) seem to differ in behavior from boost::shared_future (which is defined in 'boost::thread').
– vines
Jun 25 at 15:11
@vines Oh wow. Didn't notice that. I'll fix the answer.
– NathanOliver
Jun 25 at 15:15
Ah, found! It is stated in the first example on shared_future:use3( ftr.get() ); // second use is defined
– vines
Jun 25 at 16:23
add a comment |
By the way, a curious observation on boost::futures. The link in the answer leads to docs onboost::fibers::shared_future
, which (again!) seem to differ in behavior from boost::shared_future (which is defined in 'boost::thread').
– vines
Jun 25 at 15:11
@vines Oh wow. Didn't notice that. I'll fix the answer.
– NathanOliver
Jun 25 at 15:15
Ah, found! It is stated in the first example on shared_future:use3( ftr.get() ); // second use is defined
– vines
Jun 25 at 16:23
By the way, a curious observation on boost::futures. The link in the answer leads to docs on
boost::fibers::shared_future
, which (again!) seem to differ in behavior from boost::shared_future (which is defined in 'boost::thread').– vines
Jun 25 at 15:11
By the way, a curious observation on boost::futures. The link in the answer leads to docs on
boost::fibers::shared_future
, which (again!) seem to differ in behavior from boost::shared_future (which is defined in 'boost::thread').– vines
Jun 25 at 15:11
@vines Oh wow. Didn't notice that. I'll fix the answer.
– NathanOliver
Jun 25 at 15:15
@vines Oh wow. Didn't notice that. I'll fix the answer.
– NathanOliver
Jun 25 at 15:15
Ah, found! It is stated in the first example on shared_future:
use3( ftr.get() ); // second use is defined
– vines
Jun 25 at 16:23
Ah, found! It is stated in the first example on shared_future:
use3( ftr.get() ); // second use is defined
– vines
Jun 25 at 16:23
add a comment |
AFAIK this is legal. std::shared_future<T>::get()
says:
The behavior is undefined if
valid()
isfalse
before the call to this
function.
Going to std::shared_future<T>::valid()
it says:
Checks if the future refers to a shared state.
...
Unlike
std::future
,std::shared_future
's shared state is not
invalidated whenget()
is called.
Which would make multiple get()
calls from the same thread and on the same instance valid.
add a comment |
AFAIK this is legal. std::shared_future<T>::get()
says:
The behavior is undefined if
valid()
isfalse
before the call to this
function.
Going to std::shared_future<T>::valid()
it says:
Checks if the future refers to a shared state.
...
Unlike
std::future
,std::shared_future
's shared state is not
invalidated whenget()
is called.
Which would make multiple get()
calls from the same thread and on the same instance valid.
add a comment |
AFAIK this is legal. std::shared_future<T>::get()
says:
The behavior is undefined if
valid()
isfalse
before the call to this
function.
Going to std::shared_future<T>::valid()
it says:
Checks if the future refers to a shared state.
...
Unlike
std::future
,std::shared_future
's shared state is not
invalidated whenget()
is called.
Which would make multiple get()
calls from the same thread and on the same instance valid.
AFAIK this is legal. std::shared_future<T>::get()
says:
The behavior is undefined if
valid()
isfalse
before the call to this
function.
Going to std::shared_future<T>::valid()
it says:
Checks if the future refers to a shared state.
...
Unlike
std::future
,std::shared_future
's shared state is not
invalidated whenget()
is called.
Which would make multiple get()
calls from the same thread and on the same instance valid.
edited Jun 25 at 14:28
answered Jun 25 at 14:23
Sombrero ChickenSombrero Chicken
26.8k3 gold badges35 silver badges84 bronze badges
26.8k3 gold badges35 silver badges84 bronze badges
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%2f56756112%2fis-it-legal-to-call-shared-futureget-multiple-times-on-the-same-instance-in%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