Best method to stop a busy-waiting task?

dennistan wrote on Friday, September 04, 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);
}

rtel wrote on Friday, September 04, 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.