Quality RTOS & Embedded Software

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


Loading

Question on variables usage between threads

Posted by peyro on April 15, 2009
Hello,

I am new with FreeRtos and would like to ask maybe a basic question. Suppose I have a global routine:

void global_function(unsigned char parameter){
unsigned char var1;

var1=parameter+1;

}

And two threads, pThread1 and pThread2. Lets suppose that Thread1 just called global_function and is about to execute statement "var1=parameter+1" but is switched to Thread2 by the kernel at this time. Thread2 also calls the function global_function and is able to execute it completed.
Question is when control is given back to Thread1, it will start from the point where it was interrupted, will it have parameter and var1 in the same value it has before interrupted??? if so where these value were stored (on particular Thread1 stack?)

Thanks in advance for any information and help
peyro

RE: Question on variables usage between threa

Posted by Richard on April 15, 2009
In your example parameter and var1 are both local stack variables. In reality they could be allocated on the task stack or in register - but in either case both tasks have their own copies of the variables so there is no problem. The function is re-entrant.

If var1 was declared static or at file/global scope, then there would be only one copy of the variable and there would be a problem.

Regards.

RE: Question on variables usage between threads

Posted by peyro on April 15, 2009
Thank you very much for the clarification Richard.
peyro


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


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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 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.


Careers

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

Renesas

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