thangle wrote on Tuesday, June 28, 2011:
Hi all
i have a simply code using Mutex as following:
/-------in **main **funtion ------------------/
xMutexLed = xSemaphoreCreateMutex();
xTaskCreate( vLED1FlashTask, ( signed char * ) “tLED1”,
LED1_STACK_SIZE, NULL, tLED1_TASK_PRIORITY, ( xTaskHandle * ) NULL );
/* *********** tLED2 *********** */
xTaskCreate( vLED2FlashTask, ( signed char * ) “tLED2”,
LED2_STACK_SIZE, NULL, tLED2_TASK_PRIORITY, ( xTaskHandle * ) NULL );
-----------2 tasks ---------------
portTASK_FUNCTION( vLED1FlashTask, pvParameters )
{
while(1){
xSemaphoreTake(xMutexLed,portMAX_DELAY);
printf("— change status LED 1");
xSemaphoreGive( xMutexLed );
}
}
//
//=================
portTASK_FUNCTION( vLED2FlashTask, pvParameters )
{
while(1){
xSemaphoreTake(xMutexLed,portMAX_DELAY);
printf("— change status LED 2");
xSemaphoreGive( xMutexLed );
}
}
expected result will be:
— change status LED 1
— change status LED 2
— change status LED 1
— change status LED 2
— change status LED 1
— change status LED 2
……….
it mean that task vLED1FlashTask and task vLED2FlashTask will run in consecutively. However, actual result is vLED1FlashTask and task vLED2FlashTask **will not **run in consecutively. as:
— change status LED 1
— change status LED 1
— change status LED 1
— change status LED 1
— change status LED 2
— change status LED 1
— change status LED 2
— change status LED 2
…………………
There is any bug in FreeRTOS ?
Thanks,
Thang Le