Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/13/07 10:56
Read: times


 
#141845 - example
Responding to: ???'s previous message
Jan Waclawek said:
It does not ensure atomicity, apparently...

Atomicity has nothing to do with it. It's about how many times the variable is accessed.

But if you meant that it doesn't ensure number accesses:
I did not say that and neither did Erik because he hasn't stated whether Ralph was volatile or not.

Jan Waclawek said:
Is there any example to show that in less than - as you mention - a lot of techtalk in C99 which I wouldn't understand anyway?

Or, putting the question in other way, is there any method to ensure atomicity "automatically", at least in cases where the "read only once in C statement" (whatever it means) applies?


C99 states that accessing a volatile object is a side effect. It also states the end of every full expression is a sequence point. And finally at a sequence point all side effects of previous evaluations shall be complete and no side effects of subsequent evaluations shall have taken place.

So the following may never read Vol more than once:
volatile int Vol;
int Ralph;

Ralph = Vol;
switch(Ralph)
{
    case 1: break;
    case 2: break;
}
NB: Vol is not accessed atomically, it can be changed by the ISR between the reads of the two bytes.

List of 16 messages in thread
TopicAuthorDate
more to atomicity and such            01/01/70 00:00      
   Interesting example ...            01/01/70 00:00      
      which I did            01/01/70 00:00      
         Aside: Keil - Atomic functions            01/01/70 00:00      
            If you can afford it.            01/01/70 00:00      
         volatile            01/01/70 00:00      
            does this have some formal definition?            01/01/70 00:00      
               sequence points and side effects            01/01/70 00:00      
                  what's exactly the value of volatile, then?            01/01/70 00:00      
                     example            01/01/70 00:00      
                        bu what is it good for then?            01/01/70 00:00      
                           Ok, visualize this one            01/01/70 00:00      
                              within a loop            01/01/70 00:00      
                           Memory Mapped I/O            01/01/70 00:00      
                              OK I see it now, thanks.            01/01/70 00:00      
            volatile switch            01/01/70 00:00      

Back to Subject List