I'd say that there is racing condition on that variable. You have the same
variable in sync and async context, In that case you need to use the atomic
statement.

If you only have async functions I there should be no problem. TinyOS is
not preemptive, so it only interrupts tasks (syncronous code). Iterruptions
or async functions however you may call it, cannot interrupt one another,
because there is only one context change possible: from syncronous to
asyncronous and back.

The timer you added however is a piece of sync code that may be interrupted
by the alarms which are async. Thats why the atomic warning appears only
when you add the timer.

2012/8/28 Xiaohui Liu <whu...@gmail.com>

> Hello all,
>
> 1) I have the following code snippet:
> *uint8_t a;*
> *
> *
> *async event void Alarm1.fired() {*
> *   a = 0;*
> *}*
>
> This compiles successfully without any warning. Isn't there a racing
> condition here, between Alarm1 and itself?
>
> 2) If the following is added.
> *async event void Alarm2.fired() {*
> *   a = 1;*
> *}*
> Still, this compiles successfully without any warning. Isn't there an
> additional racing condition here, between Alarm1 and Alarm2 (and Alarm2 and
> itself)?
>
> 3) If the following is added.
> *event void Timer.fired() {*
> *  a = 2;*
> *}*
> Then there is a warning, "non-atomic accesses to shared variable `a'". Why
> is there no warning for
> *a = 0;*
> in Alarm1?
>
> According to the TinyOS book P196, a variable has to be protected by an
> atomic statement "*if it is accessed from an async function*". But seems
> to me, *"a"* is accessed from an async function in all 3 cases above and
> none is protected except
> *a = 0;*
> in Timer.
>
> Can anybody please share the experience on atomic? Thanks in advance.
>
> --
> -Xiaohui Liu
>
> _______________________________________________
> Tinyos-help mailing list
> Tinyos-help@millennium.berkeley.edu
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>
_______________________________________________
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to