Some problems about Thread Control


Our team is moving code from t-kernel to legato and has two threading problems:

  1. le_thread_Join in legato can release the resources of sub-threads in the main thread, but I hope that self-termination(use le_thread_Cancel) and deletion(Delete thread and release the space occupied by threads) can be done in sub-threads. What should I do in legato Application?

  2. There are two sets of functions in t-kernel: tk_slp_tsk() and tk_wup_tsk (tskid).They can self-suspends threads and other threads wake-up threads at specified locations, because there is no similar interface in legato. I use mutex and cond in Linux to complete this pair of interfaces.(Does using these Linux functions in legato threads cause problems?)

The other pair of interface is tk_sus_tsk (tskid) and tk_rsm_tsk (tskid), which can suspend and wake up the specified thread by passing in ID(In any thread). This seems not only impossible in legato, but also troublesome in linux. I hope to provide some ideas.

  1. You can directly use those thread api.
  2. You can have a try, i believe it is fine.


Hi @phoneixSH,

I’ve been using the Legato thread API for a while now - mostly to run some operations at different RT levels - and haven’t had too much grief. Starting and stopping them from a control thread hasn’t been an issue - although I haven’t had to pass data between the threads (I pass in setup and config data via a context at thread creation).

Two things to note:

  1. you will need to call api xxx_ConnectService() functions in your thread main for any legato APIs to attach and operate correctly (eg, if you want to use the le_cfg API, you need to call le_cfg_ConnectService()). This also goes for any private APIs that you have created yourself.
  2. you MUST have a call to le_event_RunLoop() at the end of your thread main function - or none of the legato events (timers, dfMonitors etc) will occur.

ciao, Dave


Perhaps pthread_kill(...SIGSTOP)can suspend and resume other thread unconditionally.
I will try it ,Thank you very much。


Thank you for your answer。
Question 1 has been solved。
Question 2 My description may not be very clear.
Unfortunately, in question2 ,I can’t change the logic code in any thread function. All I can do is to replace and modify the interface of the T-kernel operating system with the API of legato.(
For example:
ER tk_cre_tsk(const T_CTSK_SYSCALL *pk_ctsk) {
mTaskCtrl[taskIDCount-1].thd_ref = le_thread_Create(idStr, pk_ctsk->task, NULL);
le_thread_SetPriority(mTaskCtrl[taskIDCount-1].thd_ref, (pk_ctsk->itskpri)+LE_THREAD_PRIORITY_HIGH);
le_thread_SetStackSize(mTaskCtrl[taskIDCount-1].thd_ref, pk_ctsk->stksz);

When the upper logic calls this interface, the thread will executed the function pointer (pk_ctsk->task). I can’t predict and change the contents of this function.

So, if i want to suspend and resume other thread unconditionally, I can’t rely on the conditional variables(pthread_cond) shared by threads.

Because we can’t find a solution for the time being, we have only completed the modifications of tk_slp_tsk(suspend current thread) and tk_wup_tsk(wakeup other suspended thread), while the interface between tk_sus_tsk(suspend other thread) and tk_rsm_tsk(wakeup other suspended thread) has been abandoned temporarily.

Thank you for your answer anyway. Question 2 has been thrown to other groups for investigation.