Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: gcc compiler bad behaviour

2012-04-14 by Don Kinzer

--- In AVR-Chat@yahoogroups.com, Bob Paddock <bob.paddock@...> wrote:
>> The volatile attribute is precisely the solution for *any* 
>> situation where a variable can be changed by an outside actor
> No. http://blog.regehr.org/archives/28 "Nine ways to break your
> systems code using volatile"  See #8.
We may be arguing different points.  Consider the code below with two tasks in a preemptive task switching environment.  I don't claim that one should write task code like this.  I do claim that if one does write code like this in such an environment, myFlag *must* be volatile.

uint8_t myFlag;

void task1(void)
{
  // do something
  while (!myFlag)
    ;
  // do something else
}

void task2(void)
{
  // do something
  myFlag = 1;
  // do something else
}

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.