problem with yield

Can someone tell me what is wrong with this code. I am trying to create a busy wait function. If I call the wait function from multiple costates, the debugger reports that the costate info is trashed.

cofunc void busywait(int t)
{
int cnt;
cnt = t * 100;
while (cnt–)
yield;
}

void main()
{
for(;:wink:
{
costate {
wfd busywait(10);
}
costate {
wfd busywait(100);
}
}
}

Thanks!

I believe that you need a semicolon after “while (cnt–)” so that the loop executes a null-statement.
As written, you’re actually executing “while (cnt–) yield;” instead.

After making the same mistake I always leave whitespace before the semicolon so it’s evident in the source code. I suggest either:

while (cnt–) ;
yield;

or:

while (cnt–)
;
yield;

I cant see anything wrong with the code you have posted.
Why dont you use

waitfor (DelayMs(100));

or similar instead of writing your own arbitrary delay function?

We are bringing up new hardware and for some reason the Delay functions never timeout. This was an attempt to create a busy wait version to get around the hardware issue.