How to wake up a sleeping thread?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
jmarshellk
Posts: 3
Joined: Sat Dec 01, 2012 4:28 pm

How to wake up a sleeping thread?

Post 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 :)
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: How to wake up a sleeping thread?

Post by Tectu »

I am not 100% sure, so don't beat me when it's wrong, but regarding to the documentation, its:

Code: Select all

Thread *chThdResume(Thread *tp)   


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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: How to wake up a sleeping thread?

Post 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
Post Reply