Quality RTOS & Embedded Software

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




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




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

Latest News

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


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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