- Why is a data race an undefined behavior (UB) in C++?
Because changes from one thread may not yet be visible in another thread, and thus some results would be not defined! Thread visibility is a concept we haven't discussed yet, but the main concept is that different threads are allowed to work on their local cache data and only push the changes to the other thread caches when they are forced to do so. We can force such an update using a memory fence, and memory fencing is part of the implementation of mutexes and atomic variables. See also the response to question 10. - What is resource acquisition is initialization (RAII) (we have seen it already in Chapter 3, Deep Dive into C++ and Performance), and how is it used in QAtomicLocker?
It describes an object that initializes some resource in its constructor and deinitializes it in the destructor. The QAtomicLocker...
United States
United Kingdom
India
Germany
France
Canada
Russia
Spain
Brazil
Australia
Argentina
Austria
Belgium
Bulgaria
Chile
Colombia
Cyprus
Czechia
Denmark
Ecuador
Egypt
Estonia
Finland
Greece
Hungary
Indonesia
Ireland
Italy
Japan
Latvia
Lithuania
Luxembourg
Malaysia
Malta
Mexico
Netherlands
New Zealand
Norway
Philippines
Poland
Portugal
Romania
Singapore
Slovakia
Slovenia
South Africa
South Korea
Sweden
Switzerland
Taiwan
Thailand
Turkey
Ukraine