C ++ volatile required when rotating on boost :: shared_ptr operator bool ()?

Possible duplicate:
When to use volatile with multiple threads?

I have two threads referencing the same one 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.

EDIT: , -. , - , .

+1
2

Rant 1:

, , , . , . , .

( shared_ptr) . . . . . , .

, , , , , , " ". , , , . ( shared_ptr , .)

2:

, , , , , , NULL. , , , - -. , , ( 6 ), .

, . . . , , , .

: , . , , , .

3:

, shared . shared_ptr, . . , .

+7

, . .

: futures .

+4

Source: https://habr.com/ru/post/1785519/


All Articles