OSTimeSly parameter

Discussion to talk about software related topics only.
Post Reply
waguila
Posts: 4
Joined: Thu Jun 02, 2011 8:05 am

OSTimeSly parameter

Post by waguila »

Hello all,

Something I cant understand when using the OSTimeDly, my issue is if I pass the value 0 ticks, the thread will go from the running state to a ready state (where in my understanding is OSTimeDly(0), will make the thread to sleep for 0 tick).

Can someone explain to me when I am not understanding right.

Thank you in advance
seulater
Posts: 445
Joined: Fri Apr 25, 2008 5:26 am

Re: OSTimeSly parameter

Post by seulater »

(where in my understanding is OSTimeDly(0), will make the thread to sleep for 0 tick
you cannot sleep for 0 ticks. minimum is 1.
waguila
Posts: 4
Joined: Thu Jun 02, 2011 8:05 am

Re: OSTimeSly parameter

Post by waguila »

Yeah I found that in the documentation, but my sleep is calculated. this is why i have to sleep to 0 ticks sometimes.

this is what happened when i slept to 0 ticks , the thread changed the state to ready. is this what it says in the doc cuz i could not find such a thing.

Thanks
seulater
Posts: 445
Joined: Fri Apr 25, 2008 5:26 am

Re: OSTimeSly parameter

Post by seulater »

but my sleep is calculated. this is why i have to sleep to 0 ticks sometimes.
If you need to sleep for 0 ticks, it sounds like you might want to consider changing you code to perform the same task but in a different way to avoid this.

Maybe if you explain what you are doing, we can help you get around this.
waguila
Posts: 4
Joined: Thu Jun 02, 2011 8:05 am

Re: OSTimeSly parameter

Post by waguila »

seulater wrote:
but my sleep is calculated. this is why i have to sleep to 0 ticks sometimes.
If you need to sleep for 0 ticks, it sounds like you might want to consider changing you code to perform the same task but in a different way to avoid this.

Maybe if you explain what you are doing, we can help you get around this.

I was just trying to understand why this happens when i sleep for 0 ticks, thanks for your help.
seulater
Posts: 445
Joined: Fri Apr 25, 2008 5:26 am

Re: OSTimeSly parameter

Post by seulater »

I was just trying to understand why this happens when i sleep for 0 ticks, thanks for your help.
Maybe someone else can explain it. But be aware to use OSTimeDly(0) is not recommended.
User avatar
pbreed
Posts: 1091
Joined: Thu Apr 24, 2008 3:58 pm

Re: OSTimeSly parameter

Post by pbreed »

In all the other OS calls, semaphore, fifo, mbox etc... 0 is the flag to wait forever.....

So OSTimeDly(0); is wait forever.....

The time tick timeouts for all RTOS waits are all handled with exactly the same code....
If the timeout value is 0, do nothing, if it decrements from 1 to 0 then wake the task.....

Actual code that does this is in nburn\system\ucos.c in Function

OSTimeTick()
.
.
.
if ( ptcb->OSTCBDly != 0 )
{
if ( --ptcb->OSTCBDly == 0 )
{
/* then release the task control block... */
}
}
User avatar
Chris Ruff
Posts: 222
Joined: Thu Apr 24, 2008 4:09 pm
Location: topsail island, nc
Contact:

Re: OSTimeSly parameter

Post by Chris Ruff »

Paul

so does OSTimeDly(0) do:

1. release the task immediately (context release)
2. absolutely nothing
or
3. lock up the task forever

?

Chris
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand
User avatar
pbreed
Posts: 1091
Joined: Thu Apr 24, 2008 3:58 pm

Re: OSTimeSly parameter

Post by pbreed »

OSTimeDly(0)

->>>> lock up the task forever

Now if you call

void OSChangeTaskDly( WORD task_prio, WORD newticks );

You can wake it up again....

So if you need a pool of worker tasks one might do that, but semaphore is probably cleaner...
waguila
Posts: 4
Joined: Thu Jun 02, 2011 8:05 am

Re: OSTimeSly parameter

Post by waguila »

thank you guys i really understand it better now :) . thanks again
Post Reply