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


multiple tasks receiving from same queue

Posted by Jesper Matthiesen on November 11, 2008

what the title says, is that possible? and if so, will they all get served if at the same priority?

if it works, i guess a binary semaphore can have multiple tasks waiting to "take" it also?

i have 2 scenarios i want to solve with this:

1. have multiple tasks for picking lengthy jobs off a job queue.

2. have an interrupt "give" a binary semaphore and then have whichever task that is "woken up" figure out what the event that caused the interrupt was and then just give the semaphore back and yield if the event was for another task (the code that decides what the event was cannot be run inside an isr)..


RE: multiple tasks receiving from same queue

Posted by Dave on November 11, 2008
It is definitely possible, and the tasks get served in priority order. If a high and low priority task are blocked on the same queue and data arrives the high priority task will get the data, if the high priority task reads the queue again without blocking in between then it will also get the next data. If the high priority task blocks or delays, then the low priority task is the only task waiting on data and will get the next data to arrive.

RE: multiple tasks receiving from same queue

Posted by Jesper Matthiesen on November 11, 2008
That's great.. Too bad the documentation doesn't mention that this is permitted/possible at all.

RE: multiple tasks receiving from same queue

Posted by Jesper Matthiesen on November 12, 2008
another question:

if a task gives a semaphore that another task of the same priority is blocking to take, is the first one then preempted?


RE: multiple tasks receiving from same queue

Posted by Richard Damon on November 12, 2008
While I am not certain if there is a preemption at this point, I will point out that depending on it either way is probably a bug, since you might get a timer tick task change right afterward and get effectively the opposite behavior.

RE: multiple tasks receiving from same queue

Posted by Richard on November 12, 2008
If a task of priority x unblocks a task also of the same priority x then the unblocked task will be the next to run:

if( pxUnblockedTCB->uxPriority >= pxCurrentTCB->uxPriority )
/* Return true if the task removed from the event list has
a higher priority than the calling task. This allows
the calling task to know if it should force a context
switch now. */
xReturn = pdTRUE;

but as both tasks are the same priority then the scheduler is at liberty to choose either to run without breaking its requirements.


[ 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