Difference between semaphore and event

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Difference between semaphore and event

Jump to solution
2,316 Views
admin
Specialist II

What is the difference between semaphore and event?

Is it advisable to replace event with semaphore and vise versa?

0 Kudos
Reply
1 Solution
967 Views
DavidS
NXP Employee
NXP Employee

Hi n3prakash,

Good RTOS definitions and understanding is in the FSLMQX/doc/mqx/mqxug.pdf chapter #2.
In general an event is good to indicate an interrupt has occured and you want to notify one or more tasks that the interrupt has occured.
Semaphore good for limiting the number of tasks that can access a specific resource.  Example might be you only want two task to be able to output data on a specific UART.  If a third tasks tried to output data it would block until a semaphore became available.  A mutext is a special case of semiphore where only one task can access a resource.  Example would be a task data logging to a file where you cannot have more than one task accessing the same file.
Hope this helps.
Regards,
David

View solution in original post

0 Kudos
Reply
1 Reply
968 Views
DavidS
NXP Employee
NXP Employee

Hi n3prakash,

Good RTOS definitions and understanding is in the FSLMQX/doc/mqx/mqxug.pdf chapter #2.
In general an event is good to indicate an interrupt has occured and you want to notify one or more tasks that the interrupt has occured.
Semaphore good for limiting the number of tasks that can access a specific resource.  Example might be you only want two task to be able to output data on a specific UART.  If a third tasks tried to output data it would block until a semaphore became available.  A mutext is a special case of semiphore where only one task can access a resource.  Example would be a task data logging to a file where you cannot have more than one task accessing the same file.
Hope this helps.
Regards,
David
0 Kudos
Reply