c++ - Fixing DCLP only with volatile -


i reading article "c++ , perils of double-checked locking" explains problems in dclp.

the second part of article (where link forwards) shows how try , solve dclp merely c/c++ volatile (which know, impossible). in article writers explain how (last example number 11), write:

unfortunately, nothing address first problem—c++'s abstract machine single threaded, , c++ compilers may choose generate thread-unsafe code source mentioned, anyway. otherwise, lost optimization opportunities lead big efficiency hit. after this, we're square one. wait, there's more—more processors.

which means (if understand correctly), doesn't matter how use volatile, won't work because "c++'s abstract machine single threaded, , c++ compilers may choose generate thread-unsafe code source mentioned"

but mean "c++'s abstract machine single threaded"?!

why above examples of volatiles won't prevent reordering?

thanks!

since c++11, bold marked sentence isn´t true anymore.

what meant in past:
os/device may support multiple threads, including functions start them etc..
c++ compilers on other hand etc. "think" of single thread environments, , not aware of possible problems when using multiple threads. thread start isn´t else normal function call them, , os strange process because of call neither known nor interesting.

code reordering in single thread environments possible long reordered code parts independent each other (eg. order how variable written/read to/from makes code using variable dependent). in multithread environment, compiler can´t possibly know if , when variable influenced another thread...

now, in c++11/c++14, there os-independent support
preventing optimizations breaking threaded code.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -