When are unstable const objects needed?

When are const volatile objects needed in C ++?

Note. I understand the need for pointers in const volatile memory cells, but they do not require objects to be const or volatile .
I ask about objects that themselves are of type const volatile , for example:

 const volatile T obj; 

In what situations is this necessary or useful?

+4
source share
1 answer

There are rare cases when you really need volatile in C ++. volatile no longer useful for multithreading. From this website there are only three portable volatile uses.

Hans Böhm points out that only three portable devices are used for volatility. I will give them here:

  • mark a local variable in setjmp so that the variable does not roll back after longjmp.
  • which is modified by an external agent or, apparently, due to an erroneous memory mapping
  • naughty signal handler

So basically you only want to use other functions for parallel programming and keep volatile for these rare situations.

+1
source

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


All Articles