Quality RTOS & Embedded Software

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


Can I run more than one instance of a thread?

Posted by dibosco on January 13, 2016

Is it possible to create a generic thread that you create multiple times, but with a different passed parameter and have those tasks run independently?

Specificially I have a thread that opens a file on an SD card, reads info off the file in small chunks and sends it to another thread to process. I'd really like to be able to create that thread up to six times, each time passing the path to file on the SD card to open as the thread's parameter, then that thread pass values back to another thread via a queue. So, I could have a few files open at the same time with each instance of the SD card reading thread passing information via the [same] queue.

Once I'd finished with it, I'd then destroy the thread.

Is that possible/sensible/stupid?



Can I run more than one instance of a thread?

Posted by rtel on January 13, 2016

Yes, definitely possible, but watch out for thread safety issues when accessing the SD card. Are you using our FAT file system? If so, I think the Windows demo does just that.

As a very simple example, you could look at the LED flash standard demo (although the file is very old!). There is only one task implemented, but many instances of the task. This works because each task has its own context - its own stack and its own [virtua] set of CPU register.

Can I run more than one instance of a thread?

Posted by dibosco on January 13, 2016

I'm using the Chan FS, I didn't even know you had one as well!

I used a mutex to ensure only one thread was accessing the libraries at any time and ensure safety and it seems to be working nicely. :)

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

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


FreeRTOS and other embedded software careers at AWS.

Latest News

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.

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