user9842: I am trying to get Arduino working with Protothreads and wanted to confirm I have the basic setup correct. If I have understood the API correctly, then the following code should be what I need to start 2 concurrent threads from inside an Arduino program:
#include <pt.h>

static struct pt t1, t2;

void setup() {
    PT_INIT(&t1);
    PT_INIT(&t2);
}

void loop() {
    doSomething(&t1, 500);
    doSomethingElse(&t2, 500);
}

static int doSomething(struct pt *pt, int interval) {
    PT_BEGIN(pt);
    sleep(100);
    PT_END(pt);
}

static int doSomethingElse(struct pt *pt, int interval) {
    PT_BEGIN(pt);
    sleep(250);
    PT_END(pt);
}

Does anyone see anything that jumps out at them as missing or wrong?

user7856: Check this example: rather than sleep(), it uses PT_WAIT_UNTIL
  while(1) {
      PT_WAIT_UNTIL(pt, millis() - timestamp > interval );
      timestamp = millis();
      doSomething();
  }

That should be the proto-thread way of waiting: PT_WAIT_UNTIL will make sure that your thread sleeps in a way that allows other threads to run.
The rest looks fine, but I have not tried to run the code.

9842: <p>I am trying to get Arduino working with <a href="http://dunkels.com/adam/pt/" rel="nofollow">Protothreads</a> and wanted to confirm I have the basic setup correct. If I have understood the API correctly, then the following code should be what I need to start 2 concurrent threads from inside an Arduino program:</p>

<pre><code>#include &lt;pt.h&gt;

static struct pt t1, t2;

void setup() {
    PT_INIT(&amp;t1);
    PT_INIT(&amp;t2);
}

void loop() {
    doSomething(&amp;t1, 500);
    doSomethingElse(&amp;t2, 500);
}

static int doSomething(struct pt *pt, int interval) {
    PT_BEGIN(pt);
    sleep(100);
    PT_END(pt);
}

static int doSomethingElse(struct pt *pt, int interval) {
    PT_BEGIN(pt);
    sleep(250);
    PT_END(pt);
}
</code></pre>

<p>Does anyone see anything that jumps out at them as missing or wrong?</p>
 7856: <p>Check <a href="http://harteware.blogspot.de/2010/11/protothread-and-arduino-first-easy.html" rel="nofollow">this example</a>: rather than sleep(), it uses PT_WAIT_UNTIL</p>

<pre><code>  while(1) {
      PT_WAIT_UNTIL(pt, millis() - timestamp &gt; interval );
      timestamp = millis();
      doSomething();
  }
</code></pre>

<p>That should be the proto-thread way of waiting: PT_WAIT_UNTIL will make sure that your thread sleeps in a way that allows other threads to run.</p>

<p>The rest looks fine, but I have not tried to run the code.</p>
