Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Thread self reference

Posted by Nobody/Anonymous on October 28, 2004

How can I get the xTaskHandle for the current running thread?


RE: Thread self reference

Posted by Richard on October 28, 2004
Why do you want to do this? Functions such as vTaskSuspend( xTaskHandle) will suspend the currently executing task if NULL is passed in as the parameter. There may be a way around what you are wanting to do like this.

The xTaskHandle is just a pointer to the task control block. It's type is hidden outside of tasks.c though (it is void* outside of tasks.c). You can obtain it by adding the following function to tasks.c (I haven't tried compiling this so watch out for typos):

xTaskHandle xGetCurrentTaskHandle( void )
xTaskHandle xReturn;

xReturn = ( xTaskHandle ) pxCurrentTCB;

return xReturn;

An alternative and not very nice hack would be to simply declare:

extern volatile void * volatile pxCurrentTCB;

at the top of your application file. pxCurrentTCB will then be the handle to the currently executing task. This may cause a linker warning though and access to the extern variable would have to be only within critical regions so the first method is preferable.

RE: Thread self reference

Posted by Nobody/Anonymous on October 29, 2004

Thanks for a great RTOS. I'll try the function xGetCurrentTaskHandle().

The first reason for I need this is that our software is message based, and each message has a sender and a receiver (UML state machines). Thus, I need to know the sender's task handle when creating the message. The second is that the passive objects often use the task handle as an unique reference.

Also, the software is not all new code. It contains lots of old code written for pSOS, OSE, and eCos. Those OSes has a self reference function, and since this functions is used... well, sigh...

Best Regards

Hello Henric !!! (UML state machines)

Posted by Nobody/Anonymous on November 30, 2004
Are u aware of Dr. Miro Samek QF (quantum frame work) or have you tried replacing UML state machines with QF. If so please share u'r experience.

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

Version 10.1.0 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner