Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

DAVE™ Forum Discussions

Not applicable
Hi all,

i have some questions according thread creation of the RTOS001 App (Version 1.0.24).

In the thread Definition there is a Parameter "instance". The documentation sais: "number of posible instances".
The questions are:
How can i start the instances of a thread, or will they all be started during "osKernelStart"?

How can i get the instance number of a certain thread during runtime, or will i get different ThreadIds for different instances?

Is it possible to Hand over different arguments to the thread instances during creation?

Is it also possible to create different threads (multiple calls of "osThreadCreate") with the same execution function each with instance = 1?

Thanks for help
Thomas
0 Likes
5 Replies
Not applicable
Hi Thomas,

You may get some hints from "RTOS001_Example1".

BR,
Zain
0 Likes
Not applicable
Zain wrote:
Hi Thomas,

You may get some hints from "RTOS001_Example1".

BR,
Zain


Hi Zain,

thanks for the replay but unfortionally this example creates two threads with different thread functions with instance=1. So this is not what i am locking for.


Thanks
Thomas
0 Likes
jferreira
Employee
Employee
First like received 750 replies posted 500 replies posted
Hi Thomas,

The parameter 'number of instances' at thread definition, allows multiple threads to execute the same function.
Find attached an example that shows:
1. How to define multiple threads sharing the same function.
2. Identification of the running thread at run time.
3. Passing an argument to the thread.
4. Retarget printf to use SWO (you will need SEGGER JLink SWO Viewer tool)
5. Use of nanolib

At thread definition it is required to specify the function to be run, number of instances and stack size.
The threads are pushed into the READY list (among other preparation steps) using osThreadCreate.
You will need to start the scheduler (osKernelStart) so that the threads get scheduled and moved to the RUNNING state (only one at a time).


Best regards,
Jesus
0 Likes
Not applicable
jferreira wrote:
Hi Thomas,

The parameter 'number of instances' at thread definition, allows multiple threads to execute the same function.
Find attached an example that shows:
1. How to define multiple threads sharing the same function.
2. Identification of the running thread at run time.
3. Passing an argument to the thread.
4. Retarget printf to use SWO (you will need SEGGER JLink SWO Viewer tool)
5. Use of nanolib

At thread definition it is required to specify the function to be run, number of instances and stack size.
The threads are pushed into the READY list (among other preparation steps) using osThreadCreate.
You will need to start the scheduler (osKernelStart) so that the threads get scheduled and moved to the RUNNING state (only one at a time).


Best regards,
Jesus


Hi Jesus,

many thanks for the very percise answer. This is exactly what i am looking for.
There are two Question left:
1.
Is it possible to assign different stack sizes as well ?

2.
Is it possible to change the priority of the threads before calling osKernelStart?

In may application the thread functions are all the same, but the call trees, starting from "thread" (that means, the threads calling different functions with different stack requirements), are very different. So i have a need to assign different stack sizes and different priorities to each instance but keep the same thread function.


Many thanks for your effort
Thomas
0 Likes
jferreira
Employee
Employee
First like received 750 replies posted 500 replies posted
Hi Thomas,

Unfortunately, to my knowledge, there is no way to specify different stack size for threads sharing the same function.
Furthermore changing dynamically the stack size of a thread it is not supported. It is defined statically at compilation time.
On the other hand, it is possible to change the priority at run time using osThreadSetPriority (osThreadId thread_id, osPriority priority).

Best regards,
Jesus
0 Likes