Research on read/write methods in Embedded Linux

Source: Internet
Author: User

From: Shanghai Shangguan embedded training http://www.uplooking.sh.cn/embedded_training/tecnews/ARM/2013/0226/2210.html

When processing real-time collected and updated data, the data update speed does not match the data processing speed. In this case, data loss may result in inaccurate data processing results and even unpredictable consequences. Therefore, a mechanism is required to coordinate data update and data processing, this ensures data integrity and accuracy of processing results. As a multi-task, multi-user operating system, embedded Linux supports concurrent running of multiple processes in the system. Due to the dynamic characteristics of the process itself, it is very suitable to describe real-time data processing, the problem of synchronization and communication between Linux processes can solve the problem of real-time data processing.
In Linux, processes usually have four statuses: running (running), blocking (BLOCKED), ready (ready), and terminated. When multiple processes are executed concurrently, the competition between processes often occurs. We hope that processes can coordinate their actions so that a process can execute an action, that is, control synchronization, only when other processes are executed to a specific point. At the same time, when concurrent processes access Shared data, there should be no competition conditions. This is ensured by implementing mutex when accessing shared data, that is, data access synchronization. Linux, as an open-source and robust operating system, supports multiple platforms and has a wide range of development tools and application software. In particular, it is very suitable for embedded systems due to its core reduction features. When the real-time and accurate data requirements are high, the system often causes data loss due to the process coordination problem during data collection and processing. The classic Process Synchronization Model can solve the problem of data synchronization read/write conflicts in the embedded Linux system.
Two common strategies are called strongreadersynchronization and strongwritersynchronization )". In strong reader synchronization, the reader is always given priority. As long as the writer does not perform write operations at present, the reader can gain access. In strong writer synchronization, the writer always obtains priority, as long as the strong reader does not perform read operations, the writer can gain access. Producer-consumer synchronization is different from pure read-write synchronization. Consumers can delete or destroy resources by accessing resources.
When only one producer and consumer exist, the production process and consumption process correspond to the same data structure and share the same data space. How to coordinate the production process and consumption process so that the data used by the consumption process every time is written by the new production personnel of the production process, in addition, the newly written data of the production process will not overwrite the data that has not been read and used by the consumption process, which is a key issue for model implementation.
In the producer-a-Consumer problem model, the producer process continuously produces products and puts them into the buffer zone. The consumer process continuously removes the products from the buffer zone for consumption. When the product in the buffer zone is full, it indicates that the production speed is higher than the consumption speed and the supply is oversupply. At this time, the producer must wait for the product to be consumed. When the buffer zone is empty, it indicates that the consumption speed is higher than the production speed, when supply is in short supply, the consumer process must wait for the production of the product. Production and consumption processes must run synchronously to achieve a balance between supply and demand.
A producer-consumer problem model with a limited buffer zone is composed of several producer and consumer processes and a limited buffer pool. Each buffer zone can store one information record, and one producer produces one information record at a time. After a record is generated, the record will be written to the buffer zone after it enters an empty buffer separately. A consumer process consumes one information record at a time. When it needs to be consumed, it waits for a separate buffer to enter a full buffer and reads the records

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.