Can I access non-RT shared memory objects and mutexes from a Xenomai real time task?
2016-09-02 15:24
537 查看
I would suggest you to use Xenomai native API to create Named Pipes, such as rt_pipe_create()and so on. There is one more thing which you can use: Message Queues. However I have always chosen Named Pipe over Message Queues. Both shared memory and message queues can be used to exchange information between processes. The difference is in how they are used. Shared memory is exactly what you'd think: it's an area of storage that can be read and written by more than one process. It provides no inherent synchronization; in other words, it's up to the programmer to ensure that one process doesn't clobber another's data. But it's efficient in terms of throughput: reading and writing are relatively fast operations. A message queue is a one-way pipe: one process writes to the queue, and another reads the data in the order it was written until an end-of-data condition occurs. When the queue is created, the message size (bytes per message, usually fairly small) and queue length (maximum number of pending messages) are set. Access is slower than shared memory because each read/write operation is typically a single message. But the queue guarantees that each operation will either processes an entire message successfully or fail without altering the queue. So the writer can never fail after writing only a partial message, and the reader will either retrieve a complete message or nothing at all. Essentially, pipes - whether named or anonymous - are used like message passing. Someone sends a piece of information to the recipient and the recipient can receive it. Shared memory is more like publishing data - someone puts data in shared memory and the readers (potentially many) must use synchronization e.g. via semaphores to learn about the fact that there is new data and must know how to read the memory region to find the information. With pipes the synchronization is simple and built into the pipe mechanism itself - your reads and writes will freeze and unfreeze the app when something interesting happens. With shared memory, it is easier to work asynchronously and check for new data only once in a while - but at the cost of much more complex code. Plus you can get many-to-many communication but it requires more work again. Also, due to the above, debugging of pipe-based communication is easier than debugging shared memory. A minor difference is that fifos are visible directly in the file system while shared memory regions need special tools like ipcs for their management in case you e.g. create a shared memory segment but your app dies and doesn't clean up after itself (same goes for semaphores and many other synchronization mechanisms which you might need to use together with shared memory). Shared memory also gives you more control over buffering and resource use - within limits allowed by the OS it's you who decides how much memory to allocate and how to use it. With pipes, the OS controls things automatically, so once again you loose some flexibility but are relieved of much work. Summary of most important points: pipes for one-to-one communication, less coding and letting the OS handle things, shared memory for many-to-many, more manual control over things but at the cost of more work and harder debugging |
相关文章推荐
- Attempt to set a non-property-list object
- 最新发现:Object.defineProperty()让数组的length属性变成只读
- [教程] 《iPhone开发基础教程》《object c中文教程》(PDF) [复制链接]
- Object-C 入门 Xcode 环境详解 HelloWorld 程序
- Object-C学习笔记(一)
- OBject-c基础教程
- Object-c 学习入门教程(经典推荐)
- Object+c语法快速入门
- 学习Objective-C入门教程(全)
- 第一篇 Object-C快速入门
- Objective-C 入门教程
- object-c 入门基础篇
- [Objective-C]关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)
- 《深度探索C++对象模型》—关于对象(Object Lessons)
- 论文笔记:Faster R-CNN:Towards Real-Time Object Detection with Region Proposal Networks
- Object Detection发展介绍
- Selective Search for Object Recoginition
- javascript Object.extend的用法
- Objective-C 经典字典数组排序 - 省市区
- AttributeError: 'module' object has no attribute 'post'问题