Quality RTOS & Embedded Software

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


Loading

Best method to stop a busy-waiting task?

Posted by Dennis Tan on September 4, 2009
Hi:

If I have two tasks and one task (B) is doing a busy wait operation. What is the best method to stop the busy-waiting task from another task (A)?

I have presented two possibilities and if you know the pro and con of each please let me know. Also if you have a better method, please also let me know.

Dennis


Method 1:

Task B
{
while (1)
{
xSemaphoreTake
if (g_stop_request == true)
break;
xSemaphoreGive
vTaskDelay(1);
}
}

Task A
{
// At certain time
xSemaphoreTake
g_stop_request = true;
xSemaphoreGive
}

Method 2:

Task B
{
while (1)
{
if (xQueueReceive(qhandle, 0) == PD_True)
break;
vTaskDelay(1);
}

Task A
{
// At certain time
xQueueSend(qhandle, 0);
}

RE: Best method to stop a busy-waiting task?

Posted by Richard on September 4, 2009
Is whatever it is busy waiting for capable of generating an interrupt? If so then have the task block on a semaphore and the interrupt unblock the task using the same semaphore.

If what it is busy waiting for is coming from another task then use a queue or semaphore to block again again, but this time have the other task send to the queue or semaphore to unblock the first task.

Regards.


[ 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