In TCB, which member is unique to a task?

osmonnb wrote on Thursday, September 05, 2019:

Q1. Which struct member is unique to a task? uxTCBNumber, or uxTaskNumber?
Q2. Which Number can be assigned by user?

hs2sf wrote on Thursday, September 05, 2019:

Why dealing with internal FreeRTOS structures ?
What do you want to accomplish ? Thread local storage ? See the docs here

rtel wrote on Thursday, September 05, 2019:

uxTaskNumber is actually provided for tools writers to do as they will
with, so the question is legitimate if used for that purpose. The
answer is actually written in the source code where the structure
members are defined:

UBaseType_t uxTCBNumber; /*< Stores a number that increments each time a
TCB is created.  It allows debuggers to determine when a task has been
deleted and then recreated. */

UBaseType_t uxTaskNumber; /*< Stores a number specifically for use by
third party trace code. */

So uxTCBNumber is controlled by the kernel to ensure it is possible to
uniquely identify a task should a task be deleted and re-created with
the same handle (as the handle is just a pointer to its TCB).
uxTaskNumber on the other hand is, just for example, used by trace tools
to hold any values that are meaningful only to the trace tool - the
kernel ignores any values written there.

osmonnb wrote on Thursday, September 05, 2019:

I am writing an application which asynchronously receive byte data from a serial port. The received by is actually a number. This number is supposed to wake up a specific task. For example, if received number is 5, then Task#5 should run, so on and so forth

My idea is to “label” each task with a unique number, starting from 0.
The only way I can think of is to use TCB of a task.

Any other idea?

hs2sf wrote on Thursday, September 05, 2019:

I’d use my own task handle table setup when creating all tasks.
So you can easily map a magic number to the corresponding task.
Remember that the FreeRTOS API relies on task handles.
That’s what you need to e.g. suspend / resume tasks for whatever reason.

richard_damon wrote on Thursday, September 05, 2019:

The values in the TCB are only useful once you get to that TCB. Your Application will probably want to have an array of the Tasks Handles for you app to use, and you can then fairly easily use the index in that array to differentiate the tasks. That also says that you can limit that operation to exactly the set of tasks designed for it, and easily control what number is assigned to what task.