Zhao,
In general there is no difference between the keywords async and sync
(which is the default if you define nothing) except from where that
function can be called. An async function can never call a sync
function, but a sync function can call another sync function, or an
async function.
The async keyword is usually used to indicate that an interrupt can call
this function and nothing "bad" will happen(concurrent modification of
variables, etc), however all of that protection must be made by the
programmer, and is not automatic.
This link might be helpful for describing the async keyword.
http://mail.millennium.berkeley.edu/pipermail/tinyos-help/2003-June/001583.html
In general, there is no preemption in the standard tinyos except for
interrupts. sync functions will never preempt sync functions. It may
be possible for async functions to be prempted by other async calls.
If you read/modify a variable that is used in an async function without
the atomic { } block, i believe the compiler will generate a warning,
but I wouldn't depend on this to catch every possible race condition.
Reading section 4.5 Concurrency in the tinyos programming manual should
give you better insight into the differences between async and sync
commands.
Hope this helps,
-Paul
Zhao Stephen wrote:
Dear all,
I am reading "Tinyos Programming". I am puzzled with "async" and
"sync". The following is a snatch.
/commandresult_tSendMsg.send...{/
/if(!state){/
/state=TRUE;/
///sendapacket/
/returnSUCCESS;/
/}/
/returnFAIL;/
/}/
/ /
/If this command were async, then it's possible between the
conditional“if(!state)”and the assignment “state=TRUE”that an other
component jumps in and tries to send as well./
//
I think if the command is sync, it is also possible by interrupt. Right?
------------------------------------------------------------------------
_______________________________________________
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