I have simple code, one thread, I start it and call chThdSuspendS in this task - it works.
I can resume with chThdResume this thread, but I can't suspend it. I call chThdSuspendS in main, it return MSG_OK, but thread still working.
What is wrong ?
Code: Select all
typedef struct trg_t
{
thread_t* threadp;
} trg_t;
THD_WORKING_AREA(waThdtrg, CONFIG_trg_THD_WA_SIZE);
THD_FUNCTION(trgThd, arg)
{
trg_t *trg = arg;
//do something
chSysLock();
chThdSuspendS(&(trg->threadp)); //suspend this task
chSysUnlock();
while (1)
{
// do in while
chThdSleepMilliseconds(10);
}
}
In main
trg.threadp = chThdCreateStatic(waThdtrg, sizeof(waThdtrg), CONFIG_trg_THD_PRIORITY, trgThd, (void *) &trg);
while(1)
{
if ( (...) && trg.threadp->state == CH_STATE_SUSPENDED)
chThdResume(&(trg.threadp), (msg_t) 0);
else if(...)
{
msg_t x;
chSysLock();
x = chThdSuspendS(&(trg.threadp));
chSysUnlock();
}
}