Threads: Difference between revisions

From AMC-OS Developers
Jump to navigation Jump to search
No edit summary
No edit summary
Line 15: Line 15:
Each process is defined by a <code>TSI_ENTRY</code> containing all thread information.
Each process is defined by a <code>TSI_ENTRY</code> containing all thread information.


=== Thread ID (ITID and GTID) ===
=== Thread ID (iTID and TID) ===


An internal thread ID (ITID) is a 16-bit unsigned integer, uniquely assigned to each thread in the whole system, with a maximum of <code>TSI_MAX_THREADS</code>. The global thread ID (GTID) is a 32-bit unsigned integer composed of the PID in the 16 upper bits, and of the ITID in the 16 lower bits.
An internal thread ID (iTID) is a 16-bit unsigned integer, uniquely assigned to each thread in the whole system, with a maximum of <code>TSI_MAX_THREADS</code>. The global thread ID (TID) is a 32-bit unsigned integer composed of the PID in the 16 upper bits, and of the ITID in the 16 lower bits.


TSI maintains a linked list of unsorted used and free TIDs, allowing allocation and release of TIDs in ''O(1)'', by respectively removing or adding the TID at the beginning of the list.
TSI maintains a linked list of unsorted used and free iTIDs, allowing allocation and release of iTIDs in ''O(1)'', by respectively removing or adding the iTID at the beginning of the list.
Both list share the same global table called <code>StatusTable</code> with two initial pointers, one for the linked list of free entries (<code>firstFreeEntry</code>), one for the linked list of used entries (<code>firstUsedEntry</code>).
Both list share the same global table called <code>StatusTable</code> with two initial pointers, one for the linked list of free entries (<code>firstFreeEntry</code>), one for the linked list of used entries (<code>firstUsedEntry</code>).


Internal functions for TID management are :  
Internal functions for iTID management are :  
* ITID TSI_AllocateTID(TSI_ENTRY *)
* iTID TSI_AllocateTID(TSI_ENTRY *)
* void TSI_ReleaseTID(ITID)
* void TSI_ReleaseTID(iTID)


To get the TSI_ENTRY for a specific ITID, an index table called <code>TSI_QuickTable</code> is maintained.
To get the TSI_ENTRY for a specific iTID, an index table called <code>TSI_QuickTable</code> is maintained.

Revision as of 17:28, 29 July 2020

Thread definition in AMC-OS

A thread is an execution unit running in the context of a specific process. It is consequently limited to the address space, code, data and execution rights of its parent process.

A thread is characterized by :

  • an internal thread ID (ITID) and global thread id (GTID)
  • a task state segment (TSS) containing CPU state (registers, stack, ...)
  • scheduling data (priority flag, counter of total and remaining active time...)
  • a list of events related to the thread

Threads are managed by the TSI module (Threads System Interface).

Threads System Interface (TSI)

Each process is defined by a TSI_ENTRY containing all thread information.

Thread ID (iTID and TID)

An internal thread ID (iTID) is a 16-bit unsigned integer, uniquely assigned to each thread in the whole system, with a maximum of TSI_MAX_THREADS. The global thread ID (TID) is a 32-bit unsigned integer composed of the PID in the 16 upper bits, and of the ITID in the 16 lower bits.

TSI maintains a linked list of unsorted used and free iTIDs, allowing allocation and release of iTIDs in O(1), by respectively removing or adding the iTID at the beginning of the list. Both list share the same global table called StatusTable with two initial pointers, one for the linked list of free entries (firstFreeEntry), one for the linked list of used entries (firstUsedEntry).

Internal functions for iTID management are :

  • iTID TSI_AllocateTID(TSI_ENTRY *)
  • void TSI_ReleaseTID(iTID)

To get the TSI_ENTRY for a specific iTID, an index table called TSI_QuickTable is maintained.