A thread-safe asynchronous IO operation system

By designing a thread-safe asynchronous I/O operating system, the problems of complexity and low efficiency of I/O operation interfaces in existing technologies are solved. It realizes efficient and simplified multi-threaded I/O operations and flexible logging functions, thereby improving the parallel performance and maintainability of applications.

CN122240324APending Publication Date: 2026-06-19BEIJING LINJIN SPACE AIRCRAFT SYST ENG INST

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING LINJIN SPACE AIRCRAFT SYST ENG INST
Filing Date
2026-03-31
Publication Date
2026-06-19

AI Technical Summary

Technical Problem

In existing technologies, the blocking model of I/O operation interfaces makes it difficult to handle high concurrency requirements. The signal and slot notification mechanism of the Qt framework is complex to implement, and single-threaded I/O operations are inefficient, affecting program performance.

Method used

We design a thread-safe asynchronous I/O operating system, including I/O operation modules, thread pool management modules, and logging modules. Through a unified programming interface and multi-threading mechanism, we simplify multi-threaded asynchronous I/O programming, provide efficient parallel operations, and support configurable data logging.

🎯Benefits of technology

It simplifies the complexity of multi-threaded asynchronous I/O programming, improves the parallel efficiency of applications, supports troubleshooting software problems and recording critical data in special application scenarios, and provides flexible scalability and efficient I/O operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122240324A_ABST
    Figure CN122240324A_ABST
Patent Text Reader

Abstract

A thread-safe asynchronous I / O operating system includes an I / O operation module, a thread pool management module, and a logging module. The I / O operation module provides an interface for read and write operations to upper-layer applications. It includes a base I / O operation class and subclasses of specific categories, defining the read and write interfaces for I / O operations. Each subclass corresponds to a worker class, which implements specific I / O functions. Each subclass contains an instance of its corresponding worker class. The thread pool management module manages sub-threads, placing I / O worker objects into sub-threads of corresponding priorities. For write operations, the main thread calls the I / O object's write interface to place the write data into the message queue of the corresponding sub-thread. The sub-thread message queue follows a first-come, first-served principle, calling the corresponding worker object in the sub-thread to complete the data write operation. The operation data is recorded to a hard disk file according to a designed format, and a log parsing tool is provided for parsing the log files.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of network communication technology, specifically relating to multithreading, asynchronous I / O, and thread safety, and particularly to a thread-safe asynchronous I / O operation method. Background Technology

[0002] I / O operations are among the most frequently used operations in software. Reading data from hardware devices such as disks and network cards is an indispensable basic function for software interaction with external systems. Multithreading is an effective way to improve software performance, increase program responsiveness, efficiently utilize multi-core processors, and consume fewer system resources, especially during remote calls, fully leveraging hardware and computing resources. Implementing an efficient, stable, reliable, and simple asynchronous multithreaded I / O operation framework is of great significance for improving software quality, development efficiency, and maintainability. The C++ programming language provides basic interfaces for network communication and file reading and writing operations such as socket and file. On top of this, many application frameworks based on the C++ programming language (such as Qt) encapsulate the basic interfaces, further simplifying the I / O operation programming interface. However, the I / O operation interfaces they provide have the following problems: (1) Traditional I / O operation interfaces are based on a blocking model, which is not conducive to handling high concurrency requirements; (2) The Qt framework provides a signal and slot approach, which can realize the I / O operation call through the signal notification mechanism, which simplifies the programming interface to a certain extent. However, different I / O operation interfaces are not unified, and the implementation is still relatively complicated; (3) The programming of multi-threaded I / O operations based on the signal and slot notification mechanism is complicated, while the I / O operation implemented by a single thread will affect the program performance due to the low efficiency of I / O. Summary of the Invention

[0003] This invention utilizes a multi-threaded and thread-safe asynchronous unified programming method for multiple I / O interfaces. By designing a reasonable programming framework, a safe parallel mechanism, and a unified programming interface, it effectively simplifies the complexity of multi-threaded asynchronous I / O programming and improves the parallel efficiency of applications for multi-I / O operation applications. At the same time, it designs a configurable data recording log for I / O operations, which effectively supports the needs of software troubleshooting and key data recording in special application scenarios.

[0004] Working Principle: A thread-safe asynchronous I / O operating system, comprising an I / O operation module, a thread pool management module, and a logging module. The I / O operation module provides an interface for read / write operations to upper-layer applications. It includes a base I / O operation class and specific subclasses, defining the read / write interfaces for I / O operations. Each subclass corresponds to a worker class, which implements specific I / O functions. Each subclass contains an instance of its corresponding worker class, which runs in a sub-thread. After an upper-layer function call, the worker executes the corresponding operation in the sub-thread. The thread pool management module manages the sub-threads, placing I / O worker objects into sub-threads of corresponding priority. For write operations, the main thread calls the I / O object write interface, placing the write data into the message queue of the corresponding sub-thread. The sub-thread message queue follows a first-come, first-served principle, calling the corresponding worker object in the sub-thread to complete the data write operation. The logging module is configurable. After configuration, it logs the data read and written by I / O objects, recording the operation data to a hard disk file according to the designed format, and provides a log parsing tool for parsing the log files.

[0005] Furthermore, the I / O operation module includes: an I / O operation base class, I / O operation subclasses, and I / O operation subclass workers. The I / O operation base class defines virtual functions for I / O operations: a write operation interface, a write result signal interface, and a read operation signal interface. The I / O operation subclasses inherit from the I / O operation base class, override the operation functions, report the write result signal after completing the operation, and report the data after reading new data. Each subclass is initialized using a "key-value" parameter, where the "key-value" contains the attributes of the I / O subclass, such as the listening IP address and port. For each operation base class, a corresponding worker class is designed, which actually performs the I / O operation.

[0006] Furthermore, the main thread defines the I / O class object operation process as follows: A1: The main thread creates I / O operation subclass objects using "key-value" parameters. The "key-value" contains the subclass object's attributes and their corresponding priorities. A2: The I / O object creates a worker object that actually performs the I / O function based on the "key value" parameter, and binds the worker object's write result signal and read data signal; A3: I / O objects will obtain corresponding child threads through the thread pool management function according to their priorities, bind worker objects to the child threads of the corresponding priorities, and complete the specific I / O operations in the child threads.

[0007] Furthermore, the thread pool management module includes: child thread priorities are divided into 3 levels, and the corresponding number of child threads are created according to the thread pool size in a 5:3:2 ratio; the method for obtaining the corresponding priority child thread in this module is as follows: if the child threads of the corresponding priority in the thread pool are in an empty state, then any empty child thread is randomly returned; if all child threads of the corresponding priority have been assigned workers, then the child thread with the fewest bound workers is returned; the child thread message queue manager included in this module manages the child thread message queue, and according to the first-come, first-served principle, performs corresponding write operations on the data in the current child thread message queue in the worker, or reports the read data to the main thread.

[0008] Furthermore, the write operation process of the asynchronous I / O operation in the sub-thread is called as follows: B1: The main thread calls the write operation interface of the created I / O subclass object; B2: I / O subclass objects place write operation data into the corresponding sub-thread message queue; B3: Based on the first-come, first-served principle, the child thread message queue manager calls the worker write operation interface to complete the write operation of the message queue write operation data.

[0009] Furthermore, the logging module operates as follows: B1. When performing read and write operations, I / O workers will retrieve data and call the data recording object to record it in the log. B2. The data recording object places the data to be recorded into the message queue of the data recording sub-thread. B3. The data recording sub-thread message queue manager distributes the data to be recorded in the message queue to the data recording worker according to the first-come, first-served principle. The worker creates a file object and performs the specific data writing operation to the file. B4. The log recorder calculates the size and recording time of the data to be recorded. The data size is calculated in bytes, and the data length and time are saved to its object properties. B5. Log recorders perform write operations, saving the statistical time, data length, and data to a file.

[0010] The beneficial effects of this invention are as follows: This invention, with its unified and simple I / O operation interface, greatly simplifies the programming of upper-layer applications, reducing coding complexity. Its efficient multi-threading mechanism ensures the timeliness of I / O operations, and its unified interface provides flexible extensibility. Inheritance facilitates the extension of other I / O operations, and configurable logging supports specific use case requirements. Therefore, applying this technology to practical engineering applications is of great significance. Attached Figure Description

[0011] Figure 1 Diagram of a thread-safe asynchronous I / O operating system architecture; Figure 2 Diagram of I / O operations; Figure 3 : Defining the I / O object process diagram; Figure 4 Thread pool management module workflow diagram; Figure 5 Data reading workflow diagram; Figure 6 : Workflow diagram of thread pool management module. Detailed Implementation

[0012] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection claimed by the present invention.

[0013] like Figure 1 As shown, a thread-safe asynchronous I / O operating system includes an I / O operation module, a thread pool management module, and a logging module.

[0014] The I / O operation class module provides an interface module for reading and writing operations to the upper-layer application. It includes a base class for I / O operations and subclasses of specific categories, which define the read and write interfaces for I / O operations. Each subclass corresponds to a worker class, which implements specific I / O functions. Each subclass contains an instance of its corresponding worker class. The worker class runs in a sub-thread, and after the upper-layer function is called, the worker performs the corresponding operation in the sub-thread.

[0015] The thread pool management module manages sub-threads, placing I / O worker objects into sub-threads of corresponding priorities. For write operations, the main thread calls the I / O object's write interface to place the write data into the message queue of the corresponding sub-thread. The sub-thread's message queue follows a first-come, first-served principle, calling the corresponding worker object within the sub-thread to complete the data write operation. For read operations, the worker reports the read data through a signal queue, retrieving the data in the main thread.

[0016] The logging module is configurable. Once configured, it logs the data read and written to I / O objects, recording the operation data to a hard disk file according to the designed format, and provides a log parsing tool for parsing the log file. The logging function is placed in a separate sub-thread, and logging does not affect I / O operations.

[0017] like Figure 2 As shown, a thread-safe asynchronous I / O operation method is provided, wherein the I / O operation class includes: 1. I / O operation base class, defining virtual functions for I / O operations: write operation interface, write result signal interface, and read operation signal interface; 2. I / O operation subclasses inherit from the I / O operation base class, override the operation functions, report the write result signal after completing the operation, and report the data after reading new data; each subclass is initialized through "key-value" parameters, which contain the attributes of the I / O subclass, such as the listening IP address and port.

[0018] 3. I / O operation subclass worker: Each operation base class has a corresponding worker class designed. This class actually performs I / O operations, such as writing data into a file for file I / O.

[0019] like Figure 3 As shown, the main thread defines the I / O class object operation process as follows: 1. The main thread creates I / O operation subclass objects using "key-value" parameters. The "key-value" contains the subclass object's attributes and their corresponding priorities. 2. The I / O object creates a worker object that actually performs the I / O function based on the "key value" parameter, and binds the worker object's write result signal and read data signal; 3. I / O objects will obtain corresponding child threads through the thread pool management function according to their priorities, bind worker objects to the corresponding priority child threads, and perform specific I / O operations in the child threads.

[0020] like Figure 4 As shown, the thread pool management module includes: 1. The child thread priority in this method is divided into 3 levels, and the number of child threads with corresponding priorities are created according to the thread pool size in a ratio of 5:3:2. 2. The method for obtaining the corresponding priority child thread in this module is as follows: If the child thread of the corresponding priority in the thread pool is in an empty state, then randomly return any empty child thread; if all child threads of the corresponding priority have been assigned workers, then return the child thread with the fewest bound workers. 3. The sub-thread message queue manager included in this module manages the sub-thread message queue. Based on the first-come, first-served principle, it performs corresponding write operations on the data in the current sub-thread message queue in the worker, or reports the read data to the main thread.

[0021] The write operation process using this sub-thread for asynchronous I / O is as follows: 1. The main thread calls the write operation interface of the created I / O subclass object; 2. I / O subclass objects place write operation data into the corresponding sub-thread message queue; 3. Based on the first-come, first-served principle, the child thread message queue manager calls the worker write operation interface to complete the write operation of the message queue data.

[0022] like Figure 5 As shown, the write operation process using this sub-thread for asynchronous I / O is as follows: 1. After reading new data in a child thread, the I / O worker places the read data into the corresponding thread's message queue; 2. The thread message queue manager notifies the main thread I / O object to retrieve new data via signals. 3. The main thread I / O object obtains new data by receiving a new data signal and performs logical operations on the new data.

[0023] like Figure 6 As shown, the logging module works as follows: 1. When performing read and write operations, I / O workers will retrieve the data and call the data recording object to record it in the log. 2. The data recording object places the data to be recorded into the message queue of the data recording sub-thread; 3. The data recording sub-thread message queue manager distributes the data to be recorded in the message queue to the data recording worker according to the first-come, first-served principle. The worker creates a file object and performs the specific data writing operation to the file. 4. The log recorder calculates the size and recording time of the data to be recorded, and the data size is calculated in bytes. The data length and time are saved to the object's properties. 5. Log recorders perform write operations, saving the statistical time, data length, and data to a file.

[0024] This invention's asynchronous I / O operations unify various I / O operations (such as network communication, file reading and writing) into a single application-layer calling interface. It provides a C++ base class and specific subclasses for I / O operations, encapsulates thread pools and asynchronous operations, and allows implementation of asynchronous operations simply by declaring an object of the class and calling the object read / write interface. Data reading and execution results can be achieved by calling encapsulated signal notifications. Inheritance from the base class facilitates easy extension of I / O operation types, and the framework of this invention also provides flexible extensibility.

[0025] The asynchronous operation method of this invention encapsulates the thread pool, so the user's upper-layer application does not need to care about the sub-thread that actually performs I / O operations. By declaring objects through the provided singleton interface, calling the write operation interface will perform I / O operations in the sub-thread. Calling the result signal and read function signal will realize the acquisition of execution results and reading of I / O input data. This multi-threaded design has a lock-free thread safety mechanism, which avoids multi-threaded coordination problems and achieves efficient operation.

[0026] The asynchronous operation method of this invention adds a configurable read / write data logging function, which records the operation log to a file. The logging method also adopts the asynchronous operation method in a sub-thread. The priority design does not affect the efficiency of normal I / O operations. For special application scenarios, the logging function can be enabled. The execution process can be traced back through the data, which facilitates the needs of software troubleshooting and key data recording.

[0027] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A thread-safe asynchronous IO operation system, characterized in that, The I / O operation class module, the thread pool management module and the log recording module are included; the I / O operation class module is an interface module for providing read and write operations to an upper layer application, includes an I / O operation base class and specific classified subclasses, defines read and write interfaces of I / O operations, each subclass corresponds to a worker class, the worker class implements specific I / O function operations, each subclass includes an instantiation object of the corresponding worker class, the worker class is in a sub-thread, and after an upper layer function is called, the worker performs corresponding operations in the sub-thread; the thread pool management module manages sub-threads, places I / O worker objects into corresponding priority sub-threads, and for write operations, a main thread calls an I / O object write interface to place write data into a message queue of a corresponding sub-thread; the message queue of the sub-thread is according to a first come first served principle, and a corresponding worker object is called in the sub-thread to complete data write operations; the log recording module is configurable content, and after being configured, the log recording module records data of I / O object read and write, records operation data into a hard disk file according to a designed format, and provides a log analysis tool to analyze the log file.

2. The operating system of claim 1, wherein, The I / O operation class module includes an I / O operation base class, an I / O operation subclass and an I / O operation subclass worker; the I / O operation base class defines virtual function write operation interfaces, write result signal interfaces and read operation signal interfaces; the I / O operation subclass inherits from the I / O operation base class, rewrites operation functions, reports write result signals after operations are completed, and reports data after new data is read; each subclass is initialized through a "key value" parameter form, and the "key value" includes attributes of the I / O subclass, such as a monitored IP address and a port; the I / O operation subclass worker, each operation base class is designed to correspond to a worker class, and the class actually completes I / O operations.

3. The operating system of claim 2, wherein, The main thread defines an I / O class object operation process as follows: A1: the main thread creates an I / O operation subclass object through a "key value" parameter form, the "key value" includes attributes of the subclass object, and includes a corresponding priority; A2: the I / O object creates a worker object actually completing I / O functions according to the "key value" parameter, binds a worker object write result signal and a read data signal; A3: the I / O object acquires a corresponding sub-thread through a thread pool management function according to a priority, binds the worker object to the corresponding priority sub-thread, and completes specific I / O operations in the sub-thread. ​ ​ 4. The operating system of claim 1, wherein, The thread pool management module includes: child thread priorities are divided into 3 levels, and the number of child threads corresponding to the priority level is created according to the thread pool size in a ratio of 5:3:2; the module obtains the child thread of the corresponding priority level by: if the child thread of the corresponding priority level in the thread pool is in an empty state, then randomly returning any empty child thread; if all child threads of the corresponding priority level have been assigned workers, then returning the child thread with the fewest bound workers; the sub-thread message queue manager included in this module manages the sub-thread message queue, and according to the first-come, first-served principle, performs corresponding write operations on the data in the current sub-thread message queue, or reports read data to the main thread.

5. The operating system of claim 4, wherein, The write operation process of the asynchronous I / O operation in the sub-thread is called as follows: B1: The main thread calls the write operation interface of the created I / O subclass object; B2: I / O subclass objects place write operation data into the corresponding sub-thread message queue; B3: Based on the first-come, first-served principle, the child thread message queue manager calls the worker write operation interface to complete the write operation of the message queue write operation data.

6. The operating system of claim 1, wherein, The logging module works as follows: B1. When performing read and write operations, I / O workers will retrieve data and call the data recording object to record it in the log. B2. The data recording object places the data to be recorded into the message queue of the data recording sub-thread. B3. The data recording sub-thread message queue manager distributes the data to be recorded in the message queue to the data recording worker according to the first-come, first-served principle. The worker creates a file object and performs the specific data writing operation to the file. B4. The log recorder calculates the size and recording time of the data to be recorded. The data size is calculated in bytes, and the data length and time are saved to its object properties. B5. Log recorders perform write operations, saving the statistical time, data length, and data to a file.