Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

what is the advantage of semaphore over use of global flag

Status
Not open for further replies.

parinda

Member level 2
Joined
Jun 3, 2008
Messages
44
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,288
Location
sri lanka
Activity points
1,533
Hi all
I think this question may already arose, but didn't see a good answer. so i thought to start new thread. My problem is what is the advantage of use semaphore over global flag ?

this is the situation. in my system two tasks use single RS232 out FIFO to send data. if any one task successfully sent data then acknowledgement will receive. so one senior person told me to use semaphore for this problem. My idea was to use simple global flag as this is simple case. so i would like to know what is the advantage of use of semaphore over global flag ( i know use of global flag is bad practice except that disadvantage are there any ?).

Thank you
B.R
Parinda
 

I must be wrong, but Semaphore is in fact a global flag.


+++
 

If implemented correctly, the semaphore set/get code will prevent the possibility of "deadlock" or situation in which (2) pieces of code can think that they can have access to the resource (serial port data). If just using a global flag that can be set/reset from more than one place, then you could have a situation where one piece of code reads the flag, but before it executes a branch based onthe value, an interrupt can occur that might itself change the global flag value, and thus the first code function erronesouly assumes it knows the state of the global flag when it has in fact, been changed right under its very "nose". Depending upon the architecture of your software, this situation may be more, or less likely to occur.
 
According to me if you are using a rtos and both the tasks are critical, use semaphore the rtos takes care of the rest.
Global flag can serve the same purpose if only these two tasks are using it.However as ftsolutions says interrupts introduce many problems which cannot be predicted.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top