Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


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 ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists