- 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...
Germany
Slovakia
Canada
Brazil
Singapore
Hungary
Philippines
Mexico
Thailand
Ukraine
Luxembourg
Estonia
Lithuania
Norway
Chile
United States
Great Britain
India
Spain
South Korea
Ecuador
Colombia
Taiwan
Switzerland
Indonesia
Cyprus
Denmark
Finland
Poland
Malta
Czechia
New Zealand
Austria
Turkey
France
Sweden
Italy
Egypt
Belgium
Portugal
Slovenia
Ireland
Romania
Greece
Argentina
Malaysia
South Africa
Netherlands
Bulgaria
Latvia
Australia
Japan
Russia