Phil, I have read your TinyOS programming manual, and still have some doubt
regarding the data race conditions:

(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.

Another question is, since async event can still interrupt the atomic
section (as you mention in the manual). Assume the following async event
comes after 'a=b' assignment:  async event result_t ADC.dataReady(uint16_t
data) { a = data;}. What will happen?  What would  the excution order be?

(2) I notice many sample program does something like this:

 async event result_t ADC.dataReady(uint16_t data) {
    m_data = data;
    post sendData();
    return SUCCESS;
  }

 task void sendData() {
    .....
    atomic dmsg->data = m_data; // assume dmsg will be modified here only
 }
 what's the usage of atomic here? Since task will not preempt itself. On the
other hand, the async event can preempt the task at any time (e.g., another
dataReady event comes before task sendData excutes). It seems to me there is
no difference whether there is atomic or not.

I notice some code like Oscope added atomic in dataReady, does it make
difference?

Thanks.



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Philip
Levis
Sent: Tuesday, June 13, 2006 9:01 AM
To: Andres Aberasturi
Cc: [email protected]
Subject: Re: [Tinyos-help] NesC and TinyOS

On Jun 12, 2006, at 7:29 AM, Andres Aberasturi wrote:

>
> Hi all,
>
> We have been working with TinyOs and NesC some few months, but we 
> still have some doubts. We want to ask you the following three
> questions:
>
> 1.- In some places, we have read that events can call commands, post 
> tasks and signal other events. Also, we have read that commands can 
> call lower level commands. Then, a command cannot post a task? or 
> signal an event? is it right? We thought command can do it.

The only operation that issues a warning is when an async function calls a
sync function. For simplicity, sync functions are only safe to call when the
root of the call graph is a task. Async functions can also have interrupt
handlers are their root.

In practice, it is bad practice to signal an event (signal xxxx) inside a
command. There is nothing that prevents you from doing so, however. It is
bad practice because it can easily lead to infinite call loops. For example:

call Foo.send();
event void Foo.sendDone();


commmand void Foo.send() {
   signal Foo.sendDone();
}

The TinyOS programming manual goes into detail on this and other good/ bad
programming practices.


>
> 2.- We have read that there are two level scheduling: events and  
> tasks. We know TinyOs scheduler manages tasks which are posted, so  
> does TinyOs scheduler manage events? or are events managed like  
> commands?

The distinction is sync/async. The term "event" was overloaded in the  
original TinyOS paper to mean both "callback" and "interrupt." The  
command/event distinction means the former, the task/event  
distinction means the latter. The nesC paper and the TinyOS  
programming guide are good resources for learning about the details.


>
> 3.- If you have a task posted, could you post the same task other  
> time? We mean if we have a task in the task qeue, could we post the  
> same task again? Perhaps it is a simple question, but we think it  
> is possible that if the task is in the task qeue, we couldn't post  
> it again.
>

This depends on what version of  TinyOS you're using. In 1.x, a  
single task can have multiple outstanding posts in the task queue. In  
2.x, a task can only have one outstanding post. This latter behavior  
turns out to have a lot of nice isolation and fairness properties.  
TEP 106 has a good discussion of the tradeoffs.

Phil
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to