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


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