c++ - What's the usecase of volatile operations on std::atomic<T>? -


this question has answer here:

there has been lot of debate going on concerning usefulness of volatile in multi-threaded code. people agree, principal usecases of volatile bare metal applications such device drivers , interrupt handlers, not make variable of built-in type thread-safe. in fact, volatile has lead confusion because of this.

however, has been added function overloads of std::atomic<t> types, suggests there usecase this. usecases of these operations?

there general usefulness volatile in sense compiler must not optimise away accesses variable. however, in case, think it's because input may volatile - in case of const, can "add" not "remove" volatile attribute passed in paramater.

thus:

int foo(volatile int *a) {     ...  } 

will accept:

int x; volatile int y;  foo(&x); foo(&y); 

where if didn't write volatile, compiler should not accept foo(&y); variant.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -