Synchronization and volatile
-
Hello everyone, Through myself study and previous discussion here, I share the conclusion here that, if some object is synchronized (mutex, critical section, etc.), there is no need to add volatile keyword. Here is the reference, (refer to section volatile, Critical Sections, and Race Conditions) http://www.ddj.com/cpp/184403766 if my understanding is wrong or you have any other options, please feel free to add here. thanks in advance, George
-
Hello everyone, Through myself study and previous discussion here, I share the conclusion here that, if some object is synchronized (mutex, critical section, etc.), there is no need to add volatile keyword. Here is the reference, (refer to section volatile, Critical Sections, and Race Conditions) http://www.ddj.com/cpp/184403766 if my understanding is wrong or you have any other options, please feel free to add here. thanks in advance, George
Hey George, let me understand what's your issue against the
volatile
keyword: Did your lineage be victim of a strange anathema? :laugh: By the way, you missed to mention (if I remember well was David Crow to point it out) that main usage ofvolatile
is not synchronization. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
Hey George, let me understand what's your issue against the
volatile
keyword: Did your lineage be victim of a strange anathema? :laugh: By the way, you missed to mention (if I remember well was David Crow to point it out) that main usage ofvolatile
is not synchronization. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles]Hi CPallini, 1. I have no real issue of volatile in my work, my personal interest to learn it in depth. 2. I understand volatile has nothing directly with synchronization (compared with mutex, critical section, etc.), but it has relationship with sychronization, as mention in the article. If you read it, I think you should have some comments (whether my understanding is correct and whether you are agree with this article's points). regards, George
-
Hi CPallini, 1. I have no real issue of volatile in my work, my personal interest to learn it in depth. 2. I understand volatile has nothing directly with synchronization (compared with mutex, critical section, etc.), but it has relationship with sychronization, as mention in the article. If you read it, I think you should have some comments (whether my understanding is correct and whether you are agree with this article's points). regards, George
I'm not sure if you got the point, so I'm going to ramble on: The whole idea of
volatile
is to tell the compiler not to cache the value. On every access, the value should be checked to see if it has been modified by another thread. The old value should not be presumed correct just because the current thread hasn't modified it. Synchronization, on the other hand, is supposed to ensure that no thread is modifying a value while another thread is using it. You wouldn't want the state of an object to change while you are reading it. Hope this helps.Florin Crisan