CTL_ERROR_NO_TASKS_TO_RUN

Comments

7 comments

  • Avatar
    Casper Hedegaard

    Problem solved. My main_task (the task with the lowest priority) may not contain any wait calls.

    0
    Comment actions Permalink
  • Avatar
    Michael Johnson

    There must always be a task ready to run CTL doesn't have a built-in idle task.

    Regards

    Michael

    0
    Comment actions Permalink
  • Avatar
    Casper Hedegaard

    Okay, that explains it. Thanks.

    0
    Comment actions Permalink
  • Avatar
    Paul Corr

    Follow-up question: if I get a CTL_ERROR_NO_TASKS_TO_RUN error, can I simply return from the ctl_handle_error() handler so it'll run a task as soon as there is one available? That seems to be working for me, but not sure if that's the proper way to handle it?

    Thanks,
    Paul

    0
    Comment actions Permalink
  • Avatar
    Paul Corr

    As a follow-up, the CTL_ERROR_NO_TASKS_TO_RUN error was being caused by my delay function (WaitMS) being called before threads are started. I added code to detect that and do a "manual" wait in that case:

    void WaitMS(int nMS)
    {
      if(ctl_task_list[0].next == NULL)
      {
          // If no other tasks are running, need to do a manual wait
          DWORD dwTicksEnd;
          dwTicksEnd = GetTickCount() + nMS; // Timer ISR must be running for this to work.
          while(!IsTimeoutExpired(dwTicksEnd))
          ResetCPUWatchDog();
      }
      else
      {
          // Otherwise, use the CTL wait to allow other tasks to immediately run
          ctl_timeout_wait(ctl_get_current_time()+nMS);
      }
    }

    That's resolved the issue, but question still stands: can I simple return ctl_handle_error() if this error occurs? Assuming, of course, the code that caused it can handle the immediate resumption of execution.

    Thanks,
    Paul

     

    0
    Comment actions Permalink
  • Avatar
    Michael Johnson

    Hi Paul,

    You'll need to add the CTL sources to your project and step through to see if it's okay. I would always make the main task the lowest priority idle task.

    Regards

    Michael

    0
    Comment actions Permalink
  • Avatar
    Paul Corr

    Hi Michael,

    Thanks for the quick reply. Based on my testing, appears the answer is yes, but I'll take a look at the sources and see. The modification of my wait function above solves the immediate issue and prevents the error from happening, so at this point it's more of an intellectual question than a practical one.

    Thanks for your help!

    Paul

    0
    Comment actions Permalink

Please sign in to leave a comment.