Thread suspend

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

Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess

omcdr
Posts: 89
Joined: Wed Aug 17, 2016 3:25 pm
Has thanked: 7 times
Been thanked: 7 times

Thread suspend

Postby omcdr » Wed Feb 07, 2018 12:03 pm

How to suspend task ?
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();
      }
   }

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Thread suspend

Postby Giovanni » Wed Feb 07, 2018 1:55 pm

The reference to the thread must be initialized to NULL, this is the problem I can see.

Enable checks, assertions etc.

Giovanni

omcdr
Posts: 89
Joined: Wed Aug 17, 2016 3:25 pm
Has thanked: 7 times
Been thanked: 7 times

Re: Thread suspend

Postby omcdr » Thu Feb 08, 2018 3:03 pm

How to suspend task, if I know thread_t * ?
Can I from main suspend other task ? chThdSuspendS can suspend only current thread.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Thread suspend

Postby Giovanni » Thu Feb 08, 2018 3:11 pm

You can't suspend other tasks, by design.

Giovanni


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 23 guests