Quality RTOS & Embedded Software

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


FreeRTOS and std smart pointers

Posted by georgbat on November 16, 2017

Hello. I have a simple question - is it safe to use std::shared_ptr with FreeRTOS multithread? Compiler is arm-gcc-none-eabi.


FreeRTOS and std smart pointers

Posted by richard_damon on November 16, 2017

std::shared_ptr shouldn't have a problem. The one base issue that will need to be handled is that to use it you first will have needed to make sure that new/delete, and by normal implication malloc/free in the implementation have been made thread safe. Some libraries have some hooks that can be defined to interface with the OS to provied this ability. A generic implementation without such a hook is likely NOT thread safe.

Note, this is a library question, not a compiler issue, especially with GCC, as there are several different libraries that might be bundled with it for a given implementation.

FreeRTOS and std smart pointers

Posted by georgbat on November 17, 2017

Thank you, much!

FreeRTOS and std smart pointers

Posted by richard_damon on November 17, 2017

Thinking about this a bit, let me amend this a bit. I will presume you understand the general need to protect ANY cross task access to an object. If a given object is only referenced by smart pointers from only 1 task, this won't be an issue. If you do pass an object between tasks with a smart pointer, than even though you might end up with multiple objects as smart pointers, they will share some internal state and thus they need protection. A typical smart pointer implementation should be using atomics for the important accesses, Atomics may or may not need support from the OS, so if you will be sharing smart pointers across tasks you should look into this.

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

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

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

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

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

Cadence Tensilica Cortes

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