Cross-process event processing method and apparatus, electronic device, storage medium, and vehicle
By establishing an association between a subset of processes and the first object in shared memory, and waking up processes using condition variable signals, the problems of low efficiency and high resource consumption in existing cross-process communication are solved, and targeted event notification and timely message delivery are realized.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- APOLLO INTELLIGENT DRIVING (BEIJING) TECHNOLOGY CO LTD
- Filing Date
- 2022-08-24
- Publication Date
- 2026-05-12
AI Technical Summary
Existing cross-process communication methods based on shared memory are inefficient, consume a lot of resources during inter-process communication, and cannot provide timely notifications, especially when important messages need to be delivered in a timely manner.
By establishing an association between a subset of processes and the first object in shared memory, and using condition variable signals to wake up processes in a dormant state, targeted event notifications can be achieved, reducing the need for periodic queries of shared memory.
It reduces resource consumption, improves the efficiency of event notification, enables targeted delivery of event notifications, and solves the problem that condition variable signals cannot be used to wake up processes in a targeted manner.
Smart Images

Figure CN115373874B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more particularly to the field of inter-process communication technology. Background Technology
[0002] With the development of software and hardware, inter-process communication (IPC) is becoming increasingly widespread, and various methods for implementing IPC are emerging. Among these, IPC based on shared memory is an efficient and rapid method.
[0003] One method for cross-process communication based on shared memory is as follows: Process A and Process B share memory. Process A, which is responsible for sending notifications, writes data to memory and then updates the data identifier. Process B periodically checks the data identifier in the shared memory. If there is data, it copies the data to the process space to obtain the information.
[0004] However, this cross-process communication method still cannot meet the requirements, and how to achieve cross-process communication more efficiently still needs to be solved. Summary of the Invention
[0005] This disclosure provides a method, apparatus, device, storage medium, and vehicle for cross-process event handling.
[0006] According to one aspect of this disclosure, a cross-process event handling method is provided, comprising:
[0007] When it is necessary to send event notifications, acquire the process lock of the shared memory of the process set; the shared memory includes the first object;
[0008] If the process lock is successfully acquired, an association is established between the first object and the process subset in shared memory;
[0009] Based on shared memory condition variable signals, multiple processes in a dormant state within a process set are awakened to notify a subset of dormant processes to retrieve the event notification message content based on a first object.
[0010] According to another aspect of this disclosure, a cross-process event handling apparatus is provided, comprising:
[0011] The first acquisition module is used to acquire the process lock of the shared memory of the process set when it is necessary to send an event notification; the shared memory includes the first object;
[0012] The association module is used to establish an association between the first object and the process subset in shared memory after successfully acquiring the process lock.
[0013] The notification module is used to wake up multiple processes in a dormant state in a process set based on a shared memory condition variable signal, so as to notify a subset of processes in the dormant state to obtain the event notification message content based on the first object.
[0014] According to another aspect of this disclosure, an electronic device is provided, comprising:
[0015] At least one processor; and
[0016] The memory is communicatively connected to the at least one processor; wherein,
[0017] The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the methods of any embodiment of the present disclosure.
[0018] According to another aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are used to cause the computer to perform a method according to any embodiment of this disclosure.
[0019] According to another aspect of this disclosure, a computer program product is provided, including a computer program that, when executed by a processor, implements a method according to any embodiment of this disclosure.
[0020] According to another aspect of this disclosure, a vehicle is provided, including the aforementioned electronic equipment.
[0021] The event handling method provided in this disclosure reduces the resource consumption caused by periodic access to shared memory, improves the efficiency of event notification, solves the drawback of using condition variable signals to wake up processes in a targeted manner, and completes the targeted delivery of event notifications to a subset of processes, that is, to a specified other process, thereby improving the efficiency of cross-process event notification.
[0022] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0023] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:
[0024] Figure 1 This is a flowchart illustrating a cross-process event handling method provided in an embodiment of this disclosure;
[0025] Figure 2 This is a schematic diagram illustrating a possible application scenario provided by an embodiment of this disclosure;
[0026] Figure 3 This disclosure provides a flowchart illustrating a method for creating shared memory according to one embodiment;
[0027] Figure 4 This is a schematic diagram illustrating a possible application scenario provided by an embodiment of this disclosure;
[0028] Figure 5 This is a flowchart illustrating yet another cross-process event handling method provided in another embodiment of this disclosure;
[0029] Figure 6 This is a flowchart of yet another cross-process event handling method provided in another embodiment of this disclosure;
[0030] Figure 7 This is a diagram of an apparatus for a cross-process event handling method provided in an embodiment of this disclosure;
[0031] Figure 8 This is a block diagram of an electronic device used to implement the cross-process event handling method of the embodiments of this disclosure. Detailed Implementation
[0032] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0033] In related technologies, when performing inter-process communication, taking processes A and B as an example, process A sends messages, and process B is responsible for receiving them. Process B needs to periodically query shared memory. When there are no message updates, this periodic query operation inevitably wastes resources. Moreover, when important messages need to be delivered promptly, process B cannot obtain the messages in a timely manner due to the limitation of periodic queries. Therefore, the inter-process communication methods in related technologies still need improvement in terms of resource utilization and efficiency.
[0034] In view of this, this disclosure proposes a cross-process event handling method. This method enables targeted event notification without periodically querying shared memory data identifiers. The process set in this disclosure includes multiple processes that communicate based on shared memory. For any process in the process set, the following can be executed: Figure 1 The cross-process time processing method shown includes:
[0035] S101. When it is necessary to send an event notification, acquire the process lock of the shared memory, which includes the first object.
[0036] S102. If the process lock is successfully acquired, establish an association between the first object and the process subset in shared memory.
[0037] A process subset is a subset of the process set, and a process subset may contain one or more processes.
[0038] In this embodiment of the disclosure, a first object is provided in the shared memory. This first object is used to implement targeted delivery of event notifications. That is, the first object records the identifiers of a subset of processes that need to receive event notifications. For example, such as... Figure 2 As shown, processes A, B, and C share memory. When process A only needs to notify process B to retrieve the event notification message, process A establishes an association between process B and a first object in the shared memory. Therefore, based on the first object, process B is associated with it and can determine that it needs to retrieve the event notification message. However, process C is not associated with the first object, so process C can determine that it does not need to retrieve the event notification message.
[0039] Of course, when the process subset includes process B and process C, the first object will be associated with process B and process C, and then both process B and process C will receive the event notification message content.
[0040] Therefore, to simplify the notification complexity, this embodiment of the present disclosure can notify a process in a dormant state to read a first object from shared memory based on a condition variable signal, and then the process associated with the first object can obtain the event notification message content. Specifically, in S103, based on the shared memory condition variable signal, a process in a dormant state in the process set is woken up to notify a subset of dormant processes to obtain the event notification message content based on the first object.
[0041] To facilitate understanding, the following example illustrates how to notify a dormant process based on a condition variable signal. For instance, the initial value of a condition variable object is 0. When the value of the condition variable object is 1, a condition variable signal is sent to wake up the dormant process. When a process needs to send a notification, after acquiring the process lock and modifying the first object, it changes the value of the condition variable object to 1. The dormant process is awakened by the condition variable signal and receives the event notification. After being awakened, the condition variable object is changed back to 0, waiting for the next time the process needs to send a notification before being modified again. In this embodiment, any process can acquire the process lock and transmit event notifications to other processes based on the condition variable signal, enabling each process in the process set to send event notifications. Notifying other processes to obtain message content via the condition variable signal eliminates the need for other processes to periodically access shared memory, reducing resource consumption caused by periodic access to shared memory. Moreover, when an event notification needs to be sent, the condition variable signal can promptly notify other processes, allowing them to obtain the message content without waiting for their own access cycle, thus improving the efficiency of obtaining event notifications. Furthermore, by establishing the association between the process subset and the first associated object, the drawback of using condition variable signals to wake up processes in a targeted manner is solved, and the event notification is directed to the process subset, thus improving the efficiency of cross-process event notification.
[0042] In this embodiment of the disclosure, when any process sends an event notification, it only needs to change the content of the condition variable object to trigger the condition variable signal, thereby sending the event notification to other processes. The message content of the event notification can be in shared memory or in storage space outside of shared memory. By writing the message content to the storage space before it is written to memory, the writing and reading of the message content do not require the use of shared memory, thus avoiding situations where processes spend a long time writing to or removing from shared memory, and improving the utilization rate of shared memory.
[0043] In some embodiments, to allow for flexible creation of shared memory, this disclosure does not impose strict requirements on the process creating the shared memory. In principle, any process can independently create shared memory for a set of processes. Figure 3 As shown, the creation method provided in this embodiment includes:
[0044] S301. If the shared memory identifier determines that no shared memory has been created, call the memory creation interface to send a memory creation request.
[0045] In this process set, each process shares a memory identifier for the shared memory. Different process sets use different shared memory, and therefore, their memory identifiers are different. When any process in the same process set is not connected to the shared memory, it can attempt to obtain the memory address of the shared memory based on the memory identifier. If the attempt fails, it is determined that the shared memory has not yet been created.
[0046] Furthermore, in this embodiment of the disclosure, any process may determine that the shared memory has not yet been created when determining the shared memory corresponding to the unconnected memory identifier.
[0047] The memory creation interface can be a system-provided interface, such as the shm_open interface. Alternatively, it can be other system-provided interfaces for creating shared memory; this disclosure does not limit this type of interface.
[0048] Before the shared memory is created, multiple processes in the process set are allowed to send memory creation requests based on the memory creation interface. Therefore, only one process will be allowed to create the shared memory, while the other processes will receive a notification that the creation failed.
[0049] In practice, the shared content can be created by the first process that initiates the shared memory creation request.
[0050] S302. Receive the response information returned by the memory creation interface.
[0051] Based on the above description, the response message indicates whether the creation of shared content is allowed. Only one process among multiple processes is allowed to create shared memory, while the other processes are denied the ability to create shared memory. In other words, the other processes will receive a response message indicating that the memory creation failed.
[0052] S303. If the response information indicates that the creation of shared memory is permitted, create shared memory based on the memory identifier.
[0053] The shared memory is created based on the memory identifier of the shared memory and then initialized.
[0054] Initialization of shared memory may include:
[0055] The lock object for shared memory is initialized to ensure that only one process can acquire the process lock to gain access to the shared memory. Based on this lock object, a process needs to acquire the process lock when accessing shared memory and release the process lock when exiting shared memory.
[0056] The condition variable object in shared memory is initialized. By modifying the condition variable object, condition variable signals can be sent to other processes to pass event notifications to them.
[0057] In addition to the two objects mentioned above, the first object also needs to be initialized. For example, setting the first object to the default value means that no process needs to obtain the message content.
[0058] Of course, the above examples are only used to explain how to determine the objects that need to be initialized based on requirements. This disclosure does not impose specific limitations on the objects that need to be initialized; the objects that need to be initialized can be configured according to requirements. Some other objects that can be initialized will be mentioned in appropriate places later, and will not be elaborated here.
[0059] To facilitate other processes' understanding of the shared memory creation status, in S304 of this embodiment, when the shared memory initialization begins, the shared memory status is set to initialization in progress.
[0060] For example, the shared memory contains header identification information, and the state of the shared memory can be recorded in this header identification information. Therefore, when initializing the shared memory, the header identification information will be initialized first, indicating that initialization is in progress. Thus, in this embodiment of the disclosure, the state of the shared memory can be easily maintained based on the header identification information, and when multiple processes create the same shared memory, it is convenient for each process to understand the creation status of the shared memory.
[0061] S305 updates the shared memory status to "initialization complete" once the shared memory initialization is complete.
[0062] That is, the header identifier information of the shared memory can be updated to the initialization completed state, thereby realizing the state transition of the shared memory.
[0063] In addition to using header identification information to maintain the state of shared memory, this embodiment of the disclosure may also provide a list of shared memory locations, where the list records the memory identifiers of available shared memory. Other processes can read the contents of this list; if the list includes the memory identifiers of shared memory locations, it indicates that the shared memory is available; otherwise, it is unavailable.
[0064] When shared memory is in the initialization state, other processes cannot establish a connection with it; other processes can only connect to the shared memory when it is in the initialization completed state.
[0065] Therefore, in this embodiment of the disclosure, based on the state of the shared memory, other processes can know whether the shared memory has been created successfully, so as to use the shared memory. Besides the implementation methods described above, any method for maintaining the state of shared memory is applicable to the embodiments of this disclosure.
[0066] In this embodiment, any process in the process set can create shared memory, enabling multiple processes in the process set to compete for the creation of shared memory. Creating shared memory based on memory identifiers ensures the uniqueness of the created shared memory. Since any process can create shared memory without relying on a specific process, the creation of shared memory is more flexible. Maintaining the state information of the shared memory prevents other processes from connecting to it during initialization; connection is only allowed after initialization is complete, ensuring smooth initialization and orderly inter-process communication.
[0067] The above described the scenario where any process can create shared memory. The following describes how to establish a connection to shared memory when the received response indicates that memory creation failed. Figure 3 As shown, it also includes:
[0068] S306. Read the status of the shared memory at specified intervals until the status of the shared memory is updated to indicate that initialization is complete.
[0069] Taking header identification information as an example, if any process determines that it has failed to create shared memory, it reads the header identification information of the shared memory at specified intervals. If the status recorded in the header identification information is "initializing", it continues to read the header identification information at specified intervals until the header identification information is updated to "initialization completed", and then the operation of reading the header identification information in a loop ends.
[0070] With a short specified duration, the process can almost immediately read that the shared memory initialization is complete. Of course, the length of the specified duration involves resource consumption, and the duration can be set according to actual needs during implementation.
[0071] S307. When the shared memory status is updated to initialize complete, map the shared memory address to the process space.
[0072] In this embodiment of the disclosure, by cyclically reading the status of shared memory, the condition of shared memory can be quickly ascertained, so as to promptly determine when it is possible to connect to shared memory. Once shared memory is created, a connection is established with the shared memory by mapping it to its own process space, ensuring that cross-process communication can proceed in an orderly manner.
[0073] It should be noted that the process creating shared memory executes in parallel with other processes, with no strict dependencies between them, thus reducing timing requirements. For example, in traditional methods, a specific process creates shared memory and sends a notification of successful creation to other processes. These other processes then need to establish a connection with the shared memory based on this notification. In this embodiment, all processes in the process set attempt to create shared memory. The process that successfully creates shared memory uses the header identifier information in the shared memory to notify other processes whether the shared memory initialization is complete. Processes that fail to create shared memory repeatedly read the header identifier information and determine when to establish a connection based on its content. Compared to traditional methods, in this embodiment, processes using shared memory do not need to passively receive notifications before establishing a connection, reducing timing requirements. Furthermore, there is no need to invoke other services to notify other processes that shared memory creation is complete, thus reducing system resource usage.
[0074] It's important to note that a process set can be multiple processes that have pre-agreed upon. For example, it might be agreed that processes A, B, C, and D can share memory. After shared memory is created, any process in the process set, whether or not it is currently running, has the right to access the shared memory. For instance, before the shared memory is created, processes A, B, and C might compete to create it; after creation, they might all connect to it. After some time, when process D starts and needs to access the shared memory, process D can obtain the address of the shared memory based on its memory identifier; then, it can map the shared memory address into its own process space, thus gaining access to the shared memory.
[0075] For other processes E not in the process set, for security reasons, authentication can be performed on these processes before they can access shared memory. Alternatively, in other embodiments, any process E can be allowed to access shared memory, but the content of the event notification message is encrypted, and other processes that obtain the message content cannot understand the information. Of course, how to ensure cross-process communication security can be determined by choosing an appropriate solution based on actual needs.
[0076] In this embodiment of the disclosure, in addition to being able to autonomously create shared memory, the shared memory can also be automatically released. The shared memory is released when all connections to the shared memory are disconnected, thereby saving system resources. In some embodiments, to facilitate timely release of shared memory, the shared memory includes a second object used to record the number of processes connected to the shared memory.
[0077] The object mentioned above that initializes shared memory can also include this second object. During initialization, this second object can be initialized to its default value.
[0078] If any process decides to stop using shared memory, it reduces the number of processes recorded in the second object by a preset value; if the number of processes recorded in the second object is at a specified value after reducing the preset value, the shared memory is released. This specified value is, for example, 0, to indicate that no process needs to continue using the shared memory.
[0079] Figure 4 A diagram illustrating the process joining and leaving shared memory. Figure 4 This illustrates the process of releasing shared memory when no process is using it. For example... Figure 4 As shown, m processes are using shared memory, and the number of processes recorded in the second object is m. Another process P also wants to use shared memory. It maps the address of the shared memory to its own process space, establishes a connection with the shared memory, and changes the number of processes recorded in the second object to m+1. When all processes disconnect from the shared memory, the last process Q to disconnect from the shared memory changes the number of processes recorded in the second object to 0, and simultaneously releases the shared memory.
[0080] In this embodiment of the disclosure, any process in the process set can both send and receive event notifications, meaning that communication between processes in the process set is bidirectional. For example... Figure 5 As shown, it includes:
[0081] S501: When it is necessary to receive event notifications, acquire the process lock for shared memory.
[0082] In this embodiment, any process can be in a state where it needs to receive event notifications even when there is no need to send a message notification. To receive event notifications, this embodiment requires acquiring a process lock and switching to a state where event notifications can be received. Specifically, in S502, if the process lock is successfully acquired, the shared memory's sleep method is called to enter a sleep state. In this embodiment, when a process is in a sleep state, it consumes very few system resources, thereby reducing resource usage. Furthermore, in S503, while in a sleep state, upon receiving a condition variable signal, it enters a wake-up state.
[0083] In sleep mode, based on condition variable signals sent by other processes, the system determines that a process notification has been received and promptly switches from sleep mode to wake-up mode. Then, in S504, in wake-up mode, the event notification is processed.
[0084] In this embodiment of the disclosure, any process can enter a hibernation state by calling the shared memory hibernation method based on a process lock, thereby switching to a state where it can receive event notifications from other processes. Being in hibernation state consumes fewer resources to receive event notifications from other processes, thus saving resources and improving resource utilization while ensuring timely acquisition of event notifications.
[0085] In some embodiments, the operation of handling event notifications may be implemented as follows: Figure 5 As shown, it includes:
[0086] S5041. In the wake-up state, acquire the process lock for shared memory.
[0087] S5042, Read the first object in shared memory.
[0088] S5043. If the association with the first object is confirmed, release the process lock and obtain the message content based on the event notification. The message content is stored in a preset location.
[0089] S5044. If it is determined that the process is not associated with the first object, return to the operation of calling the sleep method of shared memory to enter the sleep state, and release the process lock.
[0090] In summary, the process determines whether to retrieve message content by checking whether it is associated with the first object, thus achieving targeted message reception; when it is not associated with the first object, it returns to a dormant state, which also reduces the use of system resources.
[0091] When a process acquires a process lock to perform read / write operations on shared memory, an internal or external error will cause the process to exit the shared memory. In the event of a failure, if the process lock is not released in time, it will lead to a deadlock, meaning no process can access the shared memory. Furthermore, when a process lock is deadlocked, if a process wants to perform read / write operations on shared memory, it needs to acquire the process lock, but if the process lock is not released, the process will remain in a state of attempting to acquire the process lock, consuming significant resources. To resolve the deadlock problem, in this embodiment, the system time can be obtained and a timeout period can be set before acquiring the process lock. If the process lock is not acquired within the timeout period, the process will terminate the process lock acquisition operation and report an error; alternatively, the process can continue to attempt to acquire the process lock, and if it still fails to acquire the process lock within the timeout period after a certain number of attempts, the process will exit the process lock acquisition operation and report an error. The system will then perform deadlock repair based on the deadlock error.
[0092] To facilitate a comprehensive understanding of the entire plan, the following will be combined with... Figure 6The entire process of completing event notification in this embodiment is described, wherein three processes—the first process, the second process, and the third process—are used on the same vehicle. Event processing includes:
[0093] S601, before the shared memory is created, the first process, the second process, and the third process respectively call the memory creation interface to send memory creation requests based on the memory identifier of the shared memory.
[0094] Suppose that the response information returned by the memory creation interface indicates that the first process created the memory, while other processes failed to create the memory.
[0095] Then in S602, the first process creates shared memory based on the memory identifier and initializes the shared memory.
[0096] S603, once the shared memory initialization is complete, the second and third processes will map the shared memory to their respective process spaces.
[0097] Suppose that the first process needs to send an event notification to the second process. The second and third processes need to receive the event notification. Then, in step S604, the second and third processes enter a sleep state.
[0098] The methods by which the S604 enters hibernation mode include:
[0099] S6041, set the system timeout period.
[0100] S6042, acquire process lock.
[0101] S6043, if the process lock acquisition fails within the timeout period, the operation exits and returns to execute S6041 after a specified interval.
[0102] S6044: Acquire the process lock within the timeout period, call the shared memory's sleep method to enter sleep state, and release the process lock.
[0103] S605: After the first process acquires the process lock, it sets the first object to be associated with the second process, wakes up the second and third processes based on the condition variable signal, and then releases the process lock.
[0104] S606: After the second and third processes are woken up, they respectively acquire process locks and read the first object in shared memory.
[0105] S607, the second process determines its association with the first object and reads the message content of the event notification.
[0106] S608, the third process is determined to be unrelated to the first object, and returns to execute S6041.
[0107] Based on the same technical concept, this disclosure also provides a cross-process event handling apparatus, such as... Figure 7 As shown, the device includes:
[0108] The acquisition module 701 is used to acquire the process lock of the shared memory of the process set when it is necessary to send an event notification; the shared memory includes a first object;
[0109] The association module 702 is used to establish an association between the first object and the process subset in shared memory when the process lock is successfully acquired.
[0110] Notification module 703 is used to wake up multiple processes in a dormant state in a process set based on a shared memory condition variable signal, so as to notify a subset of processes in the dormant state to obtain the message content of the event notification based on the first object.
[0111] In some possible embodiments, the apparatus further includes a creation module for creating the shared memory based on the following apparatus method:
[0112] If the shared memory identifier determines that the shared memory has not yet been created, the memory creation interface is called to send a memory creation request.
[0113] Receive the response information returned by the memory creation interface;
[0114] If the response information indicates that the creation of shared memory is permitted, shared memory is created based on the memory identifier;
[0115] When starting to initialize shared memory, set the shared memory status to "initializing".
[0116] Once the shared memory initialization is complete, update the shared memory status to "initialization complete".
[0117] In some possible embodiments, the device further includes:
[0118] The loop read module is used to read the status of the shared memory at specified intervals when the response information indicates that memory creation has failed, until the status of the shared memory is updated to indicate that initialization is complete.
[0119] The mapping module is used to map the memory address of shared memory to the process space when the shared memory state is updated to indicate that initialization is complete.
[0120] In some possible embodiments, the shared memory includes header identification information, and the state of the shared memory is recorded in the header identification information.
[0121] In some embodiments, the shared memory includes a second object that records the number of processes connected to the shared memory, such as... Figure 8 As shown, the device also includes:
[0122] The recording module is used to reduce the number of processes recording the second object by a preset value when it is determined that shared memory will no longer be used;
[0123] The release module is used to release shared memory when the number of processes recorded in the second object is reduced to a specified value after a preset value is reduced.
[0124] In some possible implementations, the device further includes:
[0125] The acquisition module is used to acquire the process lock for shared memory when it is necessary to receive event notifications;
[0126] The hibernation module is used to invoke the hibernation device in shared memory to enter a hibernation state after successfully acquiring the process lock;
[0127] The wake-up module is used to enter the wake-up state upon receiving a condition variable signal;
[0128] The processing module is used to handle event notifications while the device is awake.
[0129] In some embodiments, the processing module includes:
[0130] The `acquire` submodule is used to acquire the process lock for shared memory while the device is awake.
[0131] The read submodule is used to read the first object in shared memory;
[0132] The message acquisition submodule is used to release the process lock and retrieve the message content based on the event notification, after determining that it is associated with the first object;
[0133] The hibernation submodule is used to return the operation of the hibernation device that called the shared memory to enter hibernation state when it is determined that it is not associated with the first object, and to release the process lock.
[0134] The specific functions and examples of each module and submodule of the apparatus in this disclosure can be found in the relevant descriptions of the corresponding steps in the above method embodiments, and will not be repeated here.
[0135] According to embodiments of this disclosure, this disclosure also provides a vehicle including an electronic device for a cross-process event processing method. In some embodiments, the vehicle proposed in this disclosure can be any vehicle equipped with a cross-process event processing device.
[0136] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.
[0137] Figure 8 A schematic block diagram of an example electronic device 800 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0138] like Figure 8 As shown, device 800 includes a computing unit 801, which can perform various appropriate actions and processes based on a computer program stored in read-only memory (ROM) 802 or a computer program loaded from storage unit 808 into random access memory (RAM) 803. RAM 803 may also store various programs and data required for the operation of device 800. The computing unit 801, ROM 802, and RAM 803 are interconnected via bus 804. Input / output (I / O) interface 805 is also connected to bus 804.
[0139] Multiple components in device 800 are connected to I / O interface 805, including: input unit 806, such as keyboard, mouse, etc.; output unit 807, such as various types of monitors, speakers, etc.; storage unit 808, such as disk, optical disk, etc.; and communication unit 809, such as network card, modem, wireless transceiver, etc. Communication unit 809 allows device 800 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0140] The computing unit 801 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 801 performs the various methods and processes described above, such as cross-process event handling methods. For example, in some embodiments, the cross-process event handling method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on device 800 via ROM 802 and / or communication unit 809. When the computer program is loaded into RAM 803 and executed by the computing unit 801, one or more steps of the cross-process event handling method described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to perform cross-process event handling methods by any other suitable means (e.g., by means of firmware).
[0141] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations may include: implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0142] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0143] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0144] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0145] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.
[0146] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.
[0147] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.
[0148] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the principles of this disclosure should be included within the scope of protection of this disclosure.
Claims
1. A cross-process event handling method, comprising: Acquire the process lock for the shared memory of the process set when it is necessary to send event notifications; The shared memory includes a first object; the first object records the identifiers of a subset of processes that need to obtain the event notification; If the process lock is successfully acquired, an association between the first object and the process subset is established in the shared memory; Based on the condition variable signal of the shared memory, wake up multiple processes in the process set that are in a dormant state, so as to notify the process subset of the multiple processes in the dormant state to obtain the message content of the event notification based on the first object; The shared memory also includes a second object, which is used to record the number of processes connected to the shared memory. The method further includes: If it is determined that the shared memory will no longer be used, the number of processes recorded by the second object will be reduced by a preset value; If the number of processes recorded by the second object is reduced to a specified value after the preset value is reduced, the shared memory is released.
2. The method of claim 1, further comprising creating the shared memory based on the following method: If the shared memory has not yet been created based on its memory identifier, a memory creation request is sent by calling the memory creation interface. Receive the response information returned by the memory creation interface; If the response information indicates that the creation of the shared memory is permitted, the shared memory is created based on the memory identifier; When the shared memory begins initialization, the state of the shared memory is set to initialization. Once the shared memory initialization is complete, the status of the shared memory is updated to "initialization complete".
3. The method according to claim 2, further comprising: If the response information indicates that memory creation has failed, the status of the shared memory is read at specified intervals until the status of the shared memory is updated to indicate that initialization is complete. When the shared memory status is updated to initialization complete, the memory address of the shared memory is mapped to the process space.
4. The method according to claim 2 or 3, wherein, The shared memory includes header identification information, and the status of the shared memory is recorded in the header identification information.
5. The method according to any one of claims 1-3, further comprising: When it is necessary to receive event notifications, acquire the process lock of the shared memory; If the process lock is successfully acquired, the sleep method of the shared memory is invoked to enter a sleep state; Upon receiving a condition variable signal, it enters a wake-up state; In the wake-up state, process the event notification.
6. The method according to claim 5, wherein, The process of handling the event notification while in the wake-up state includes: In the awakened state, acquire the process lock of the shared memory; Read the first object from the shared memory; If the association with the first object is determined, the process lock is released, and the message content is obtained based on the event notification; If it is determined that the process is not associated with the first object, the operation of calling the sleep method of the shared memory to enter the sleep state is returned, and the process lock is released.
7. A cross-process event handling apparatus, the apparatus comprising: The first acquisition module is used to acquire the process lock of the shared memory of the process set when it is necessary to send an event notification; The shared memory includes a first object; the first object records the identifiers of a subset of processes that need to obtain the event notification; An association module is used to establish an association between the first object and the process subset in the shared memory when the process lock is successfully acquired. The notification module is used to wake up multiple processes in the process set that are in a dormant state based on the condition variable signal of the shared memory, so as to notify the subset of processes in the dormant state to obtain the message content of the event notification based on the first object. The shared memory further includes a second object, which is used to record the number of processes connected to the shared memory. The device also includes: The recording module is used to reduce the number of processes recorded by the second object by a preset value when it is determined that the shared memory will no longer be used; The release module is used to release the shared memory when the number of processes recorded by the second object is reduced to a specified value after the preset value is reduced.
8. The apparatus of claim 7, further comprising a creation module for creating the shared memory based on the following method: If the shared memory has not yet been created based on its memory identifier, a memory creation request is sent by calling the memory creation interface. Receive the response information returned by the memory creation interface; If the response information indicates that the creation of the shared memory is permitted, the shared memory is created based on the memory identifier; When the shared memory begins initialization, the state of the shared memory is set to initialization. Once the shared memory initialization is complete, the status of the shared memory is updated to "initialization complete".
9. The apparatus according to claim 8, further comprising: The loop read module is used to read the status of the shared memory at specified intervals when the response information indicates that memory creation has failed, until the status of the shared memory is updated to indicate that initialization is complete. The mapping module is used to map the memory address of the shared memory to the process space when the state of the shared memory is updated to initialization complete.
10. The apparatus according to claim 8 or 9, wherein, The shared memory includes header identification information, and the status of the shared memory is recorded in the header identification information.
11. The apparatus according to any one of claims 7-9, further comprising: The second acquisition module is used to acquire the process lock of the shared memory when it is necessary to receive event notifications; The hibernation module is used to invoke the hibernation device of the shared memory to enter a hibernation state when the process lock is successfully acquired. The wake-up module is used to enter the wake-up state upon receiving a condition variable signal; The processing module is used to process the event notification when the system is awake.
12. The apparatus according to claim 11, wherein, The processing module includes: The acquisition submodule is used to acquire the process lock of the shared memory in the wake-up state; The read submodule is used to read the first object in the shared memory; The message acquisition submodule is used to release the process lock and acquire message content based on the event notification when it is determined that the process is associated with the first object. The hibernation submodule is used to return the operation of the hibernation device that called the shared memory to enter hibernation state when it is determined that it is not associated with the first object, and to release the process lock.
13. An electronic device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-6.
14. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-6.
15. A computer program product comprising a computer program that, when executed by a processor, implements the method according to any one of claims 1-6.
16. A vehicle comprising the electronic device of claim 13.