Possible duplicate:When to use volatile with multiple threads?
I have two threads referencing the same one boost::shared_ptr:
boost::shared_ptr
boost::shared_ptr<Widget> shared;
The thread rotates, expecting another thread to reset boost::shared_ptr:
while(shared) boost::thread::yield();
And at some point another thread will call:
shared.reset();
My question is, do I need to declare a generic pointer how volatileto prevent the compiler from optimizing the call shared.operator bool()from the loop and never detect changes? I know that if I just looped on a variable, waiting until it reaches 0, I would need it volatile, but I'm not sure that it is boost::shared_ptrimplemented in such a way that it is not needed here.
volatile
shared.operator bool()
EDIT: , -. , - , .
, , , . , . , .
( shared_ptr) . . . . . , .
, , , , , , " ". , , , . ( shared_ptr , .)
, , , , , , NULL. , , , - -. , , ( 6 ), .
, . . . , , , .
: , . , , , .
, shared . shared_ptr, . . , .
shared
shared_ptr
, . .
: futures .
Source: https://habr.com/ru/post/1785519/More articles:How to get only top-level text content of node using getTextContent () - javaSetting page title in static page view - phpMPMoviePlayerController iPhone 3G and .mov format - iphonememcpy () security in adjacent memory areas - c ++Can XStream be configured to use bidirectional (parent / child) links? - javaXcode error while trying to view .xcdatamodel - iosHow to catch and handle errors in Make? - error-handlingCreate a view controller with parameters - objective-cTripleDES Encryption in C # and PHP doesn't work the same (PKCS7, ECB)? - c #С# ASCII GetBytes, как установить, какой символ используется для неузнаваемого преобразования? - c++All Articles