std::get on different elements: thread-safety

50 views
Skip to first unread message

Marco

unread,
Dec 1, 2016, 8:32:16 AM12/1/16
to ISO C++ Standard - Discussion
As discussed up in this SO question I'd be interested into knowing whether there's anything in the standard (or anything pending) that more closely regards concurrency and thread-safety for std::tuple and std::get. I couldn't find anything aside from container.requirements.dataraces which I suppose do not apply here.

Nicol Bolas

unread,
Dec 1, 2016, 11:22:01 AM12/1/16
to ISO C++ Standard - Discussion
On Thursday, December 1, 2016 at 8:32:16 AM UTC-5, Marco wrote:
As discussed up in this SO question I'd be interested into knowing whether there's anything in the standard (or anything pending) that more closely regards concurrency and thread-safety for std::tuple and std::get. I couldn't find anything aside from container.requirements.dataraces which I suppose do not apply here.

Since there is no specific statement on dataraces with these functions, then it would follow the general standard library rules on data races, as outlined in [res.on.data.races]/2-3.

Basically, so long as that thread is the only one accessing that particular tuple object, then it's fine. But accessing the same object, even with different values for the index, is not thread-safe. But if you access it in a `const` way, then it's fine.

Now, perhaps it should be protected. I'm not sure if such a change ought to be considered a defect or a proposal. But it seems clear that, with the current wording, it is not protected.

Greg Marr

unread,
Dec 1, 2016, 4:05:16 PM12/1/16
to ISO C++ Standard - Discussion
I thought that it was safe to access different fields in the same object as long as those fields weren't part of a bitfield.

Richard Smith

unread,
Dec 1, 2016, 4:15:59 PM12/1/16
to std-dis...@isocpp.org
The non-const get could, in principle, modify other internal members of the tuple object (perhaps in some kind of debugging stl implementation).

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+unsubscribe@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.

Reply all
Reply to author
Forward
0 new messages