Trouble in MQX IO driver

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Trouble in MQX IO driver

ソリューションへジャンプ
1,464件の閲覧回数
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,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 件の賞賛
返信
3 返答(返信)
1,112件の閲覧回数
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,113件の閲覧回数
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,112件の閲覧回数
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 件の賞賛
返信