Trouble in MQX IO driver

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

Trouble in MQX IO driver

跳至解决方案
1,463 次查看
bluehacker
Contributor III

I read MQX io driver such as uart driver, and find one question.

it seems all driver don't count synchronization between more than one task .

for example, if task A is calling the uart driver's write routine to send some data, but when task A doesn't finish send all data, it is been preempted by task B .

suppose task B also call the driver's write routine, also send some data.  then confict occurs. the receiver will get a part of data which is send by task A, and another part of data sent by task B

 

I am not sure my question is a really trouble 

0 项奖励
回复
1 解答
1,111 次查看
DavidS
NXP Employee
NXP Employee

Hi Bluehacker,

The drivers are safe but you can have multiple task call the same driver.  So the better answer is that the way the drivers are setup is that they are flexible enough to allow multiple task to call them safely but that may not be what you want from a system point of view.  If you want more than one task to access the driver and you want them to have synchronization, then you need to implement it using Mutex or Sempahore or global variable.

Hope that helps.

Regards,

David

 

在原帖中查看解决方案

0 项奖励
回复
3 回复数
1,111 次查看
bluehacker
Contributor III

My question is actually  The MQX io driver  is thread-safe??

We can call driver in more than one task without synchroniaztion?

 

0 项奖励
回复
1,112 次查看
DavidS
NXP Employee
NXP Employee

Hi Bluehacker,

The drivers are safe but you can have multiple task call the same driver.  So the better answer is that the way the drivers are setup is that they are flexible enough to allow multiple task to call them safely but that may not be what you want from a system point of view.  If you want more than one task to access the driver and you want them to have synchronization, then you need to implement it using Mutex or Sempahore or global variable.

Hope that helps.

Regards,

David

 

0 项奖励
回复
1,111 次查看
BryGuyH
Contributor IV

To answer the OPs question... No you have to do the thread safety yourself.

 

The MQX I/O subsystem is agnostic regarding renentrancy, leaving thread safety up to the individual drivers. However because MQX does support several priority inversion mitigation techniques you can easily modify the BSP to incorporate semiphores or mutexes in the open, read, write, and ioctl driver interfaces without significantly altering the overall system behavior.

 

Most of the drivers provided in the example BSPs are not threadsafe - the caveat being they do guard against allowing an open without a close - so if you don't pass the MQX_FILE_PTR to the driver (the return pointer from an fopen) around to multiple threads and make sure to null it when you close a driver you should be fine.

0 项奖励
回复