On Jun 13, 2006, at 10:41 AM, David Gay wrote:
---------- Forwarded message ----------
From: David Gay <[EMAIL PROTECTED]>
Date: Jun 13, 2006 10:41 AM
Subject: Re: [Tinyos-help] NesC and TinyOS
To: Adam <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED]
On 6/13/06, Adam <[EMAIL PROTECTED]> wrote:
(1)
void foo()
{
c = d;
}
......
atomic
{
a = b;
foo();
}
.......
First question is: does atomic protect the variable in both side.
In this
example, are all variables (a,b,c,d) protected? Or just a and c are
protected.
All variables are protected. Atomic statements are defined to be
"serialisable", i.e., you can assume nothing else happens during the
execution of an atomic statement (and, in fact, they are simply
implemented by disabling interrupts...).
Another question is, since async event can still interrupt the atomic
section (as you mention in the manual).
Async events cannot interrupt atomic statements.
I think the confusion comes from the distinction between the
semantics of atomic (the theory) and what TinyOS does to achieve
these semantics (the practice).
David's first statement (serialisability) is how atomic behaves
semantically. As atomic sections are defined to be serializable, then
code in atomic section cannot be interrupted by code that modifies
anything which might alter its result: it must behave as if there
were no preemption, but rather a completely serial execution order.
In practice, the way TinyOS/nesC achieves this is to globally disable
interrupts. However, if it were running on more complex hardware
(e.g., with interrupt priority level disabling) then it *could* do
something more complex without violating its semantic requirements.
As the manual goes into, two atomic interrupts that never touch each
other could *in theory* preempt one another. In practice, however,
they do not.
Phil
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help