How does a thread suspend itself?

Hi,

(I'm assuming that the main() function of an application is actually executed as a thread.)  I can't find any clear documentation that describes how a thread can suspend itself via k_thread_suspend().  What's the value of the "thread" argument in this case?

Thanks,

Dave

Parents
  • Hi,

    Typically, from the thread itself you would like to take a semaphore (k_sem_take()) or suspend for a given amount of time before the thread automatically resumes (k_sleep()). Sometimes you just want other threads to start executing, if there are any, and therefore stop the execution of the current thread early (yield()). Sometimes you might want the thread to stop and never start again (return from the entry point function of the thread).

    If you want to suspend the thread from itself, then you can do so with k_thread_suspend(), yes, but please note that then some other thread must later call k_thread_resume() on the thread for it to get back from the suspended state. The argument for k_thread_suspend(), of type k_tid_t, is the thread ID which you got from the call to k_thread_create(). From within the thread itself, you can get this ID from a call to k_current_get().

    Regards,
    Terje

Reply
  • Hi,

    Typically, from the thread itself you would like to take a semaphore (k_sem_take()) or suspend for a given amount of time before the thread automatically resumes (k_sleep()). Sometimes you just want other threads to start executing, if there are any, and therefore stop the execution of the current thread early (yield()). Sometimes you might want the thread to stop and never start again (return from the entry point function of the thread).

    If you want to suspend the thread from itself, then you can do so with k_thread_suspend(), yes, but please note that then some other thread must later call k_thread_resume() on the thread for it to get back from the suspended state. The argument for k_thread_suspend(), of type k_tid_t, is the thread ID which you got from the call to k_thread_create(). From within the thread itself, you can get this ID from a call to k_current_get().

    Regards,
    Terje

Children
No Data
Related