2017年10月30日 星期一

[ThreadX, 3] thread

Thread State


TCB(Thread control block):
  • context switch用來保存thead狀態
  • 可在記憶體任何地方(user自行分配)
  • read only
  • Debug(tx_api.h)
tx_thread_run_count
Thread's run counter
tx_thread_state
Thread's execution state
TX_READY
TX_COMPLETED
TX_TERMINATED
TX_SUSPENDED
TX_SLEEP
TX_QUEUE_SUSP
TX_SEMAPHORE_SUSP
TX_EVENT_FLAG
TX_BLOCK_MEMORY
TX_BYTE_MEMORY
TX_MUTEX_SUSP

Note:
  1. 沒有executestate當正在執行時或剛createthread ready
    1. 若設了TX_DONT_START則為SUSPEND
  1. task return 狀態為 TX_COMPLETED


Thread Services
Thread service
 Description
tx_thread_create
 Create an application thread

Note: return is TX_THREAD (TCB)
tx_thread_delete
Delete an application thread

只在TX_COMPLETED/TX_TERMINATED狀態下操作
tx_thread_entry_exit_notify
 Notify application upon thread entry and exit
tx_thread_identify
Retrieves pointer to currently executing thread
tx_thread_info_get
Retrieve information about a thread

資訊與TCB相似
tx_thread_performance_info_get
 Get thread performance information
tx_thread_performance_system_info_get
 Get thread system performance information
tx_thread_preemption_change
Change preemption-threshold of application
thread
tx_thread_priority_change
 Change priority of an application thread

會將thread priority thresholddisable
tx_thread_relinquish
Relinquish control to other application threads

cooperative multi-tread(a round-robin scheduling)
tx_thread_reset
 Reset thread to original status
tx_thread_resume
 Resume suspended application thread
tx_thread_sleep
 Suspend current thread for specified time( unit: ticks)
tx_thread_stack_error_notify
Register thread stack error notification callback
tx_thread_suspend
 Suspend an application thread
tx_thread_terminate
 Terminates an application thread
tx_thread_time_slice_change
 Changes time-slice of application thread
tx_thread_wait_abort
 Abort suspension of specified thread

無法恢復被強制supspendthread(tx_thread_suspend)




Tips
  • how to fine tune stack size ?
    • 宣告一足夠大的stack並填上特定值(0xEFEF)
    • create thread and run
    • 完整測試
    • 查看有多少stack沒被用到
  • Reentrant
    • thread其中一個特點是,同一個function可能會有多個thread來使用,此時就需要保證為reeentrant,其中:
      • 不能使用靜態變數(global, static)

沒有留言:

張貼留言