Are volatile reads and writes atomic on Windows+VisualC?
There are a couple of questions on this site asking whether using a volatile variable for atomic / multithreaded access is possible: See here, here, or here for example.Now, the C(++) standard...
View ArticleAnswer by jcoder for Are volatile reads and writes atomic on Windows+VisualC?
Yes they are atomic on windows/vc++ (Assuming you meet alignment requirements etc or course)However for a lock you would need an atomic test and set, or compare and exchange instuction or similar, not...
View ArticleAnswer by Tobias Schlegel for Are volatile reads and writes atomic on...
As of Visual C++ 2005 volatile variables are atomic. But this only applies to this specific class of compilers and to x86/AMD64 platforms. PowerPC for example may reorder memory reads/writes and would...
View ArticleAnswer by Maxim Egorushkin for Are volatile reads and writes atomic on...
A bit off-topic, but let's have a go anyway.... there are the docs for The Interlocked* functions, especially InterlockedExchange which takes a volatile(!) variable ...If you think about this:void...
View ArticleAnswer by Alexandre C. for Are volatile reads and writes atomic on...
The point is probably to allow stuff likesingleton& get_instance(){ static volatile singleton* instance; static mutex instance_mutex; if (!instance) { raii_lock lock(instance_mutex); if (!instance)...
View ArticleAnswer by Necrolis for Are volatile reads and writes atomic on Windows+VisualC?
under x86, these operations are guaranteed to be atomic without the need for LOCK based instructions such as Interlocked* (see intel's developer manuals 3A section 8.1):basic memory operations will...
View Article