Quantcast
Channel: User HolyBlackCat - Stack Overflow
Viewing all articles
Browse latest Browse all 1370

Answer by HolyBlackCat for read from file to a struct containing an atomic variable

$
0
0

I believe the bool itself is more problematic than std::atomic here.

Regardless of what std::is_trivially_copyable says for std::atomic (which seems to be a subject of a defect report), it should be safe in practice, as long as you don't have any concurrent accesses to the same variable. Access through [unsigned] char is exempt from strict aliasing, and I don't think there's any platform that stores anything else in std::atomic in addition to the value it contains (as long as the type is small enough to make atomic lock-free). There may or may not be some quirk in the standard that makes it technically illegal, but it would be a purely theoretical issue.)

A bigger problem is that if you read an invalid bit pattern into a bool (not 0 or 1), the code using it might break in unexpected ways.


Viewing all articles
Browse latest Browse all 1370

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>