FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [February 2015 Threads]
Hi all,
It is neccesary to use mutexes or another method to protect this kind of variables?
volatile bool bflag = FALSE;
Task1:
...
bflag = TRUE;
...
Task2:
...
if (bflag == TRUE)
{
bFlag = FALSE;
}
...
It is this the following solution OK?
Task1:
bool localflag;
TakeMutex();
localflag = bFlag;
GiveMutex();
if (localflag == TRUE)
{
localflag = FALSE;
}
Task2:
TakeMutex();
bFlag = TRUE;
GiveMutex();
Could be any difference between using boolean type var and any other type?
Thanks in advance
If one task was only reading, and one task was only writing, then you would not need any mutual exclusion. As it is both tasks are writing to the variable, so you might need mutual exclusion.
If both tasks could write to the variable at the same time then you would need some form of mutual exclusion.
If only one task could write to the variable at a time then you would not need mutual exclusion. For example if Task 1 only wrote when the variable was FALSE, and task 2 only wrote when the variable is TRUE.
In any case a mutex is way too heavy for just setting a variable. Writing to a variable is very quick, so it is probably more appropriate to use a simple critical section.
taskENTERCRITICAL();
bFlag = TRUE;
taskEXITCRITICAL();
Regards.
Thanks for your quick response!
Regards
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.