Page 1 of 1
How to wake up a sleeping thread?
Posted: Thu Dec 13, 2012 7:25 am
by jmarshellk
Dear All,
I have a question, I use chThdSleep(TIME_INFINITE) to suspend a thread,
what syntax I must use to wake up this thread?
Supposed I have 2 thread, and I want to wake up one of them.
Thank you for your help

Re: How to wake up a sleeping thread?
Posted: Thu Dec 13, 2012 8:06 am
by Tectu
I am not 100% sure, so don't beat me when it's wrong, but regarding to the
documentation, its:
The callgraph says that it invokes
Code: Select all
void chSchWakeupS(Thread *ntp, msg_t msg)
So that just seems to be fine for me.
~ Tectu
Re: How to wake up a sleeping thread?
Posted: Thu Dec 13, 2012 8:59 am
by Giovanni
Hi,
A thread sleeping in chThdSleep() is not meant to be woken from another thread (even if calling chSchWakeupS() would work).
Consider the use of a semaphore initialized to zero, chSemInit(&sem, 0), in this role, chSemWait(&sem) waits on the semaphore, chSemReset(&sem, 0) wakes up all threads waiting resetting the semaphore to zero.
Giovanni