Separated asynchronous multi-thread communication framework

By designing a separate asynchronous multi-threaded communication framework, the component number management mechanism is used to achieve efficient communication between components, solving the complexity and efficiency of multi-threaded communication, improving development efficiency and ensuring system stability.

CN119201069AInactive Publication Date: 2024-12-27中船九江海洋装备(集团)有限公司
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411373678.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-29
Publication Date
2024-12-27
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

When the existing multi-threaded communication design takes into account both the software operation efficiency and development efficiency, it is difficult to achieve efficient and low-coupled asynchronous communication between components, resulting in difficulty in data interaction and message interaction, high complexity, and affect development efficiency.

Method used

Design a separate asynchronous multi-threaded communication framework, which provides message data structure and module manager through component number management mechanism, realizes efficient communication between components, simplifies the communication process between threads, and enables communication between components through component numbering, and within the framework Manage inter-thread communication details.

Benefits of technology

It realizes efficient communication between components, reduces the complexity of concurrent programming, improves development efficiency, and avoids system crashes caused by thread resource competition through modular design and resource management mechanisms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201069A_ABST
    Figure CN119201069A_ABST
Patent Text Reader

Abstract

The invention discloses a separated asynchronous multi-thread communication framework. The framework comprises a component number, a message data structural body, a component base class, a message module base class, module management and component number management. Each module is in two-way communication with the separated asynchronous multi-thread communication framework, and each component is in two-way communication with the module. The framework adopts a separated design, so that the components are separated, and the framework is built on the basis of multiple threads, so that the components can work in different threads. Besides, the modules are invisible to the components, communication between the components is carried out through component numbering, so that communication between the components is easier, and upper software development can pay more attention to development of the components instead of complex multi-thread communication. The method is suitable for the design of a multi-thread software communication framework and is used for realizing the separation between the components, the multi-thread communication framework provides high-level abstraction, and the complexity of concurrent programming is simplified.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of calculation, deduction or counting technology, and specifically relates to a separated asynchronous multi-threaded communication framework. Background Art

[0002] Multithreading technology can be traced back to the early days of computer science. With the improvement of processor performance and the popularization of multi-core architecture, multithreading has become increasingly important as a concurrent execution model. Multithreading allows a program to execute multiple tasks at the same time, significantly improving the responsiveness and efficiency of applications. In the single-core era, thread switching achieved through time slice rotation allows programs to exhibit parallel execution characteristics on a macro level. However, true concurrency was not achieved until the emergence of multi-core processors, because multiple physical cores can process different threads at the same time.

[0003] Conventional inter-thread communication usually involves synchronization mechanisms to avoid data contention and deadlock situations, which increases the complexity of program design. In a multi-threaded environment, threads may need to access shared resources or exchange information, which requires developers to use tools such as locks, semaphores, and conditional variables to ensure data consistency and atomicity of operations. However, improper synchronization control may lead to race conditions or deadlocks, making debugging difficult. In addition, excessive synchronization may also introduce additional performance overhead, such as context switching and waiting time, affecting program efficiency. Summary of the invention

[0004] The present invention provides a separated asynchronous multi-threaded communication framework, which aims to design an efficient and low-coupling asynchronous multi-threaded communication method, and provide a communication implementation reference for the separation between components. In order to solve the problems of data interaction and message interaction difficulties, communication speed and communication convenience in the existing asynchronous multi-threaded communication in the software development process, a message communication framework design based on component numbering is adopted. Traditional multi-threaded communication problems are difficult to design, and it is impossible to take into account the operating efficiency and development efficiency of the software at the same time. In order to solve the above problems, a unique component number is assigned to each message component. Through the framework design, the components are separated. While ensuring the communication efficiency, the software development pays more attention to the development of the component itself, rather than complex multi-threaded communication.

[0005] The present invention provides a separated asynchronous multi-threaded communication framework. The framework realizes efficient communication between various components of multi-threads through a message management mechanism, provides interfaces for various modules and components, manages modules through a module manager, assigns a component number to each component, and manages the component number through a component number manager. Communication between components is collected and distributed through the module manager. All of the above operations are completed within the framework, so upper-level software development does not need to consider these issues, and only needs to divide modules and components according to actual functions and perform functional development on components to improve development efficiency.

[0006] In order to achieve the above purpose, the technical solution of the present invention is: a separated asynchronous multi-threaded communication framework, including component numbering, message data structure, component base class, message module base class, module management and component number management.

[0007] The component number is an enumeration value, and the component number enumeration value of each module is allocated. The component number enumeration value of each component needs to be within the allocation range of the module.

[0008] The message data structure is mainly used to transmit messages between components. Its main contents include the component number of the message receiver, the component number of the message sender and the data carried by the message, which are associated with the component number.

[0009] The component base class is the communication subject, which has the functions of sending, receiving, registering and deregistering messages, is associated with the component number, and depends on the component number and the message data structure. The subclasses of the component base class are the implementation subjects of each function, and the base class provides the subclasses with the ability to communicate in the framework.

[0010] The message module base class is the main body of thread classification and depends on the message data structure. The subclasses of the message module base class are the implementation bodies of each thread. Each module runs in an independent thread and is responsible for the initialization of thread internal data and message processing. The base class provides thread running preparation, message processing preparation, and initialization preparation for the subclass. Therefore, in the module, only the initialization of each thread-specific functional component needs to be completed.

[0011] The module management is responsible for managing the modules in the entire system, including module registration, destruction and module information distribution, relying on the message data structure and combined in the message module base class.

[0012] The component number management is responsible for the registration, deregistration, and pointer acquisition of all components, and is dependent on and combined with the component number and message data structure.

[0013] The communication method of the communication framework is as follows: the design of the components is separated; each module communicates bidirectionally with the separated asynchronous multi-threaded communication framework, and each component communicates bidirectionally with the module. The framework adopts a separated design, the module is invisible to the component, and the communication between components is carried out through the component number.

[0014] Components can work in different threads; the subclasses of the message module base class are the implementation entities of each thread. Each module runs in an independent thread and is responsible for initializing the thread's internal data and processing messages.

[0015] Beneficial effects of the present invention:

[0016] A separated asynchronous multi-threaded communication framework provided by the present invention is suitable for the design of multi-threaded software communication framework. Communication between components does not need to consider communication between threads. It only needs to assign the receiving component number to the receiving party component number in the message data structure to achieve separation between components. The multi-threaded communication framework provides a high-level abstraction, simplifies the complexity of concurrent programming, and the modular design of the communication framework enables the system to easily expand new functions or services as needed. At the same time, the communication framework provides an effective resource management mechanism to ensure that threads will not cause system crashes due to resource competition. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 It is a schematic diagram of the communication method of the separated asynchronous multi-threaded communication framework.

[0018] Figure 2 It is a separated asynchronous multi-threaded communication framework and some application functional class diagrams.

[0019] Figure 3 This is a communication flow chart of the separated asynchronous multi-threaded communication framework. DETAILED DESCRIPTION

[0020] It should be understood that the specific implementation examples described herein are only used to explain the present invention and are not used to limit the present invention.

[0021] The following is a further description of a separated asynchronous multi-threaded communication framework of the present invention in conjunction with specific embodiments.

[0022] like Figure 1 As shown, each module communicates bidirectionally with the separated asynchronous multi-threaded communication framework, and each component communicates bidirectionally with the module. The framework adopts a separated design, the module is invisible to the component, and the communication between components is carried out through the component number.

[0023] like Figure 2As shown in the figure, the whole software is divided into two parts, one is the separated asynchronous multi-threaded communication framework, and the other is the application function implementation area. The separated asynchronous multi-threaded communication framework includes component number (EMSG), message data structure (SMsg), component base class (MsgRS), message module base class (MsgModule), module management (ModuleManager) and component number management (IdManager). The application function implementation area can focus more on the development of the component itself rather than complex multi-threaded communication.

[0024] The component number (EMSG) is an enumeration value. By allocating the component number enumeration value to each module, the component number enumeration value of each component needs to be within the allocation range of the module.

[0025] The message data structure (SMsg) is mainly used to transmit messages between components. Its main contents include the component number of the message receiver, the component number of the message sender and the data carried by the message, which is associated with the component number (EMSG).

[0026] The component base class (MsgRS) is the communication subject, which has the functions of sending, receiving, registering and unregistering messages. It is associated with the component number (EMSG) and depends on the component number (EMSG) and the message data structure (SMsg). The subclasses of the component base class (MsgRSA1, MsgRSA2, MsgRSB1, MsgRSB2) are the implementation subjects of each function. The base class provides the subclasses with the ability to communicate in the framework.

[0027] The message module base class (MsgModule) is the main body of thread classification and depends on the message data structure (SMsg). The subclasses of the message module base class (MsgModuleA, MsgModuleB) are the implementation bodies of each thread. Each module runs in an independent thread and is responsible for initializing the thread's internal data and processing messages. The base class provides thread running preparation, message processing preparation, and initialization preparation for the subclass. Therefore, in the module, only the initialization of the specific functional components of each thread needs to be completed.

[0028] Module Manager (ModuleManager) is responsible for managing modules in the entire system, including module registration, destruction and module information distribution. It relies on the message data structure (SMsg) and is combined in the message module base class (MsgModule).

[0029] The component number management (IdManager) is responsible for the registration, deregistration, and pointer acquisition of all components. It depends on the component number (EMSG) and the message data structure (SMsg), and is combined with the component number (EMSG) and the message data structure (SMsg).

[0030] Moreover, outside the separated asynchronous multi-threaded communication framework, the subclasses of the message module base class (MsgModuleA, MsgModuleB) are associated with the subclasses of the component base class (MsgRSA1, MsgRSA2, MsgRSB1, MsgRSB2), but the subclasses of the message module base class (MsgModuleA, MsgModuleB) are not visible to the subclasses of the component base class (MsgRSA1, MsgRSA2, MsgRSB1, MsgRSB2), so the subclasses of the component base class (MsgRSA1, MsgRSA2, MsgRSB1, MsgRSB2) can only communicate through their respective IDs.

[0031] like Figure 3 , the communication steps under the communication framework are as follows:

[0032] Step 1: Preparation.

[0033] Step 1-1: The message module base class derives the message module class and registers the message module into the module management.

[0034] Step 1-2: Derive the component class from the component base class, implement the component class as a member variable implemented by the message module class, and register it with the component number.

[0035] Step 1-3: Start the message module.

[0036] Step 1-4: Repeat steps 1-1, 1-2, and 1-3 as needed to complete the construction of each component.

[0037] Step 2: Inter-component communication process, component A sends a message to component B. You only need to mark component B in the message body and call the sending function of the component base class to complete component A sending a message to component B. In the framework, the steps are as follows:

[0038] Step 2-1: Find the corresponding message module according to the target component number and put the message into the corresponding thread-safe queue.

[0039] Step 2-2: Wait for the module to get the message, parse the component number, and distribute the message to component B.

[0040] Step 2-3: Component B receives and processes the message.

[0041] The above method realizes one-time communication between components and thread-safe communication within the framework. Outside the framework, you only need to call the send function of the component base class, and the communication between threads is easy to implement.

Claims

1. A separated asynchronous multi-threaded communication framework, characterized in that: Contains component number, message data structure, component base class, message module base class, module management and component number management; The component number is an enumeration value. By allocating the component number enumeration value of each module, the component number enumeration value of each component needs to be within the allocation range of the module; The message data structure is mainly used to transmit messages between components. Its main contents include the component number of the message receiver, the component number of the message sender, and the data carried by the message, which are associated with the component number; The component base class is the communication subject, which has the functions of sending, receiving, registering and unregistering messages. It is associated with the component number and depends on the component number and the message data structure. The subclasses of the component base class are the implementation subjects of each function. The base class provides the subclasses with the ability to communicate in the framework. The message module base class is the main body of thread classification and depends on the message data structure; the subclasses of the message module base class are the implementation bodies of each thread. Each module runs in an independent thread and is responsible for the initialization of thread internal data and message processing. The base class provides thread running preparation, message processing preparation, and initialization preparation for the subclass. Therefore, in the module, only the initialization of each thread-specific functional component needs to be completed; Module management is responsible for managing modules in the entire system, including module registration, destruction and module information distribution. It depends on the message data structure and is combined in the message module base class. Component number management is responsible for the registration, deregistration, and pointer acquisition of all components. It depends on the component number and message data structure and is combined with the component number and message data structure.

2. A separated asynchronous multi-threaded communication framework according to claim 1, characterized in that: The components are designed to be separate; each module communicates bidirectionally with the separate asynchronous multi-threaded communication framework, and each component communicates bidirectionally with the module; the framework adopts a separate design, the modules are invisible to the components, and communication between components is carried out through component numbers.

3. A separated asynchronous multi-threaded communication framework according to claim 1, characterized in that: Components can work in different threads; the subclasses of the message module base class are the implementation entities of each thread. Each module runs in an independent thread and is responsible for initializing the thread's internal data and processing messages.

Citation Information

Patent Citations

  • Online game message interaction protocol on mobile platform based on CS architecture

    CN101094227A

  • Message processing method and message center system

    CN104243274A

  • A Linux-based inter-thread communication system

    CN109408248A

  • Multi-thread program architecture method and architecture system

    CN110175071A