Difference between semaphore and event

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Difference between semaphore and event

跳至解决方案
3,431 次查看
admin
Specialist II

What is the difference between semaphore and event?

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

0 项奖励
回复
1 解答
2,082 次查看
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 项奖励
回复
1 回复
2,083 次查看
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 项奖励
回复