Multi-process synchronization system and related equipment thereof

Through the initialization, join synchronization and all arrival synchronization interfaces in the multi-process synchronization system, combined with semaphores and counters, the complexity of multi-process concurrent execution is solved, efficient multi-process synchronization and rollback processing are achieved, and the system complexity is reduced. .

CN118796492APending Publication Date: 2024-10-18南昌勤胜电子科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410864824.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-28
Publication Date
2024-10-18

AI Technical Summary

Technical Problem

It is difficult to efficiently and simply implement multiple processes to execute concurrently to a specified location and then continue concurrent execution with the existing technology, resulting in increased program complexity and a heavy workload of reconstruction.

Method used

Provides a multi-process synchronization system, including initialization interface, joining synchronization interface and all arrival synchronization interface. Through limited semaphores and counters, it ensures that an indefinite number of multi-processes are synchronized at designated positions, and supports process rollback processing to reduce multiple points. Synchronization system complexity.

Benefits of technology

It achieves efficient concurrent execution of multiple processes at designated locations, simplifies synchronization system design, supports process rollback, and improves the fault tolerance and reliability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118796492A_ABST
    Figure CN118796492A_ABST
Patent Text Reader

Abstract

According to the multi-process synchronization system and the related equipment provided by the invention, when a plurality of processes need to be synchronized, the multi-process synchronization system provided by the embodiment of the invention can use a limited and determined number of semaphores to cooperate with counting, so that the synchronization processing efficiency is improved. According to the multi-process synchronization system provided by the embodiment of the invention, multiple processes with an indefinite number are ensured to be concurrently executed to a specified position and then continuously concurrently executed, and the multi-process synchronization system provided by the embodiment of the invention is irrelevant to the position and the number of times of use for process synchronization. After initialization is completed, point positions needing to be synchronized are added to reach an interface at the same time, and then the effect that multiple running examples of one program or multiple different examples of multiple processes all reach semantics can be achieved. According to the method, the synchronous function of any multiple synchronous point locations among multiple existing processes can be realized simply and conveniently, the defect that a kernel object is applied for each synchronous point location in the existing synchronization technology is avoided, and the design complexity of a multi-point synchronization system is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of process synchronization processing, and in particular to a multi-process synchronization system and related equipment. Background Art

[0002] In actual application, the automated testing field of production testing such as mobile phones, smart watches, and bracelets often involves the simultaneous startup of multiple interfaces on the same computer for the same automated testing program. By configuring different parameters for each startup instance, multiple DUTs can be tested in parallel to improve the test efficiency. For example, the general execution process of the transmitter and receiver test of a mobile phone is to cyclically execute the transmission and reception tests of each frequency band. In this process, the comprehensive tester needs to be used to measure the transmission of uplink and downlink signals. When testing the transmitter, only one DUT can be tested at the same time. For the receiving test, as long as the instrument transmits the downlink signal, multiple DUTs can receive the signal at the same time to achieve parallel testing. In the process of multiple rounds of transmitter and receiver tests being executed continuously, multiple mobile phones can be tested simply by mutually exclusive time-sharing. For the receiver test, multiple test processes can be run in parallel until the comprehensive tester transmits the signal, and then the DUT receiving test action is executed concurrently. Multiple mobile phones share the downlink signal, and the test efficiency is improved in parallel. Therefore, in order to achieve the purpose of parallel execution of multiple DUTs during the receiving test, it is necessary to implement the execution of all processes until the instrument transmits the downlink signal and then start concurrent execution at the same time. In actual applications, the number of sub-processes that can be tested in parallel is uncertain, which further increases the complexity of program development.

[0003] In order to ensure that multiple processes continue to execute concurrently after reaching a specified position, the existing technical solutions generally use one process to implement the entire process, put the processes that need to be executed in parallel into different threads, and wait for multiple threads to complete before continuing the execution of subsequent processes. However, the parallel execution process requires the creation and execution waiting of multiple parallel process threads. Each additional synchronization point requires repeated thread creation. The more points that need to be reached, the more complicated the program is. For the single-threaded execution process that has been developed to be transformed into multi-process collaborative work, the workload of reconstructing multiple processes that need to reach more points synchronously is large. Therefore, how to efficiently and easily achieve the concurrent execution of multiple processes after reaching a specified position and continuing the concurrent execution is a problem that people have always been concerned about. Summary of the invention

[0004] The present application aims to solve at least one of the above-mentioned technical defects. In view of this, the present application provides a multi-process synchronization system and related equipment to solve the technical defect in the prior art that it is difficult to efficiently and easily realize the concurrent execution of multiple processes after reaching a specified position and continuing the concurrent execution.

[0005] A multi-process synchronization system, including: an initialization interface, a join synchronization interface, and a full arrival synchronization interface;

[0006] The initialization interface is responsible for initializing the fields of the process to be synchronized;

[0007] The join synchronization interface is responsible for setting the join synchronization process flags of all processes to be synchronized to 1, so as to include all processes to be synchronized into a set of processes to be synchronized, wherein the set of processes to be synchronized includes at least one process to be synchronized;

[0008] The all-arrived synchronization interface is responsible for determining the synchronization position where all the processes to be synchronized need to arrive; and at the synchronization position where all the processes to be synchronized need to arrive, multi-process synchronization is performed on all the processes to be synchronized in the set of processes to be synchronized according to a preset synchronization strategy.

[0009] Preferably, the system further comprises a fallback interface;

[0010] When a process rollback is required, the rollback interface is responsible for setting the value of the process rollback depth counter of the currently executed process to a preset first threshold, and setting the value of the process execution progress counter of the currently executed process to a preset second threshold;

[0011] Wherein, the preset first threshold is set to the number of all arrival synchronization interfaces spanned by the backoff;

[0012] The preset second threshold is set as the difference between the original value of the process execution progress counter of the currently executed process and twice the preset first threshold.

[0013] Preferably, the process of performing multi-process synchronization on all the processes to be synchronized in the set of processes to be synchronized according to a preset synchronization strategy at the synchronization position where all the processes to be synchronized need to arrive at by the all-arrived synchronization interface includes:

[0014] According to the synchronization position that all the processes to be synchronized need to reach, check whether the values ​​of the process execution progress counters of all the processes to be synchronized are 0 or 1;

[0015] If the values ​​of the process execution progress counters of all processes to be synchronized are 0 or 1, the waiting state parameter of the currently executed process is restored to 0;

[0016] Increment the value of the process execution progress counter of the currently executed process by 1. If the value of the process rollback depth counter of the currently executed process is non-zero, decrement the value of the process rollback depth counter of the currently executed process by 1.

[0017] Set the row corresponding to the process number of the currently executing process in the semaphore array to the signaled state;

[0018] Check whether the wait state parameter of the currently executed process is 0;

[0019] If the wait state parameter of the currently executed process is 0, check whether there is a process whose process rollback depth counter value is not 0 among all the processes to be synchronized;

[0020] If the wait state parameter of the currently executed process is non-zero, then count the number of processes whose initialization state parameter is 1 and whose wait state parameter is 0 among all the processes to be synchronized;

[0021] If the number of processes whose initialization state parameter is 1 and whose waiting state parameter is 0 among all the processes to be synchronized is 0, the waiting state parameters of all the processes to be synchronized are set to 0, and the operation of checking whether the waiting state parameter of the currently executed process is 0 is returned;

[0022] If there is no process whose process rollback depth counter value is non-0 among all the processes to be synchronized, non-rollback processing is performed, and the value of the process execution progress counter of the currently executed process is incremented by 1;

[0023] If there is a process whose process rollback depth counter value is non-0 among all the processes to be synchronized, then determine whether the value of the process rollback depth counter of the currently executed process is non-0;

[0024] If the value of the process rollback depth counter of the currently executed process is 0, the operation of checking whether the wait state parameter of the currently executed process is 0 is returned to be executed.

[0025] Preferably, the process non-rollback processing includes:

[0026] Determine the value of the process execution progress counter of the first target process whose process execution progress counter has the maximum value among all processes whose process rollback depth counters have the value of 0; and calculate a first difference between the value of the process execution progress counter of the currently executed process and the value of the process execution progress counter of the first target process;

[0027] Determine whether the first difference is less than -2;

[0028] If the first difference is less than -2, the waiting state parameter of the currently executing process is set to 1;

[0029] If the first difference is greater than -2, in the column corresponding to the process number of the currently executed process in the semaphore array, the row indexes corresponding to the process numbers of all processes whose first difference is greater than -2 are used to select the semaphore set for waiting;

[0030] Determine whether the waiting time of the currently executed process exceeds a preset first time length;

[0031] If the waiting time of the currently executed process does not exceed the preset first time, the column corresponding to the process number of the currently executed process in the semaphore array is set to a no-signal state;

[0032] If the waiting time of the currently executed process exceeds the preset first time, returning to execute the operation of checking whether the waiting state parameter of the currently executed process is 0;

[0033] If the first difference is equal to -2, the column corresponding to the process number of the currently executed process in the semaphore array is set to a no-signal state.

[0034] Preferably, if the value of the process rollback depth counter of the currently executed process is non-zero, the process rollback processing is performed through the rollback interface.

[0035] Preferably, the process non-rollback processing includes:

[0036] Determine the value corresponding to the process rollback depth counter of the process whose process rollback depth counter has the maximum value among all processes to be synchronized, and respectively calculate the second difference between the value of the process rollback depth counter of all processes whose process rollback depth counters have non-zero values ​​and the value of the process rollback depth counter of the maximum value, and return to execute the determination whether the value of the process rollback depth counter of the current process is the minimum and only value of the process rollback depth counter among all processes to be synchronized;

[0037] If the process rollback depth counter of the currently executed process is the smallest and only value of the process rollback depth counter among all the processes to be synchronized, then returning to execute the operation of checking whether the wait state parameter of the currently executed process is 0;

[0038] If the value of the process rollback depth counter of the currently executed process is not the smallest and only value of the process rollback depth counter among all the processes to be synchronized, then determine the third difference between the value of the process rollback depth counter of the currently executed process and the value of the process rollback depth counter of the process whose process rollback depth counter value is the maximum value among all the processes to be synchronized; and subtract the second difference value of each process other than the currently executed process among all the processes to be synchronized from the third difference value, respectively, to obtain a fourth difference between the second difference value of each process other than the currently executed process among all the processes to be synchronized;

[0039] Determine that the rows corresponding to the process numbers of all processes corresponding to the fourth difference being less than or equal to 2 and the columns corresponding to the process number of the currently executed process are indexed to extract the first semaphore set for waiting;

[0040] Determine whether the waiting time of the currently executed process for the first semaphore set exceeds a preset second time;

[0041] If the waiting time of the currently executed process for the first semaphore set does not exceed the preset second time, the column corresponding to the process number of the currently executed process in the semaphore array is set to a no-signal state, and the process execution progress counter of the currently executed process is decremented by 1;

[0042] If the waiting time of the currently executed process for the first semaphore set exceeds the preset second time, the operation of checking whether the waiting state parameter of the currently executed process is 0 is returned to be executed.

[0043] Preferably, the system further comprises an exit synchronization interface;

[0044] When all processes to be synchronized have completed synchronization and no further process synchronization is required, the exit synchronization interface is responsible for restoring the currently executing process to the initial state, setting the waiting state parameters of all processes to 0, and setting all signals in the index row of the currently executing process in the signal matrix to a no-signal state.

[0045] Preferably, the preset first duration and the preset second duration are set according to the process synchronization test scenario requirements.

[0046] A multi-process synchronization device, comprising: one or more processors, and a memory;

[0047] The memory stores computer-readable instructions, and when the computer-readable instructions are executed by the one or more processors, the execution steps of the multi-process synchronization system as described in any one of the above introductions are implemented.

[0048] A readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by one or more processors, the one or more processors implement the execution steps of the multi-process synchronization system as described in any of the above introductions.

[0049] It can be seen from the technical solution introduced above that when multiple processes need to be synchronized at the same synchronization arrival synchronization position, an embodiment of the present application can provide a multi-process synchronization system, which can initialize the interface, join the synchronization interface, and arrive at the synchronization interface; wherein, the initialization interface can be responsible for initializing the fields of the process to be synchronized; the join synchronization interface can be responsible for setting the join synchronization process flag of all processes to be synchronized to 1, so that all processes to be synchronized can be included in the process set to be synchronized, wherein the process set to be synchronized includes at least one process to be synchronized; after determining all processes that need to be synchronized, the all arrival synchronization interface can be responsible for determining the synchronization position where all processes to be synchronized need to arrive; and at the synchronization position where all processes to be synchronized need to arrive, according to the preset synchronization strategy, multi-process synchronization is performed on all processes to be synchronized in the process set to be synchronized. It can be seen that when multiple processes need to be processed synchronously, the multi-process synchronization system provided by the embodiment of the present application can use a limited and determined number of semaphores, in conjunction with the use of counts, to achieve a method of ensuring that an indefinite number of processes continue to execute concurrently after executing concurrently to a specified position, and the multi-process synchronization system provided by the embodiment of the present application is not related to the position and number of times used for process synchronization. After completing the initialization interface and adding the synchronization interface call, by adding all arrival synchronization interfaces at the points where synchronization is required, the effect of all arrival semantics of multiple running instances of a program or multiple different instances of multiple processes can be achieved, and multiple processes can be efficiently synchronized and processed synchronously, effectively reducing the complexity of the design of the multi-point synchronization arrival system. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0051] Figure 1 A schematic diagram of a system architecture for implementing multi-process synchronization provided in an embodiment of the present application;

[0052] Figure 2 A schematic diagram of the effect of shared memory distribution of an initialization interface application as an example of an embodiment of the present application;

[0053] Figure 3 A schematic diagram of an implementation logic of a full-reach synchronization interface exemplified in an embodiment of the present application;

[0054] Figure 4A schematic diagram of a process of synchronizing all arrivals of multiple processes as exemplified in an embodiment of the present application;

[0055] Figure 5 The present invention is a hardware structure block diagram of a multi-process synchronization device disclosed in an embodiment of the present application. DETAILED DESCRIPTION

[0056] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0057] In order to ensure that multiple processes continue to execute concurrently after reaching a specified position, the existing technical solutions generally include the following two solutions:

[0058] Solution 1: Use one process to implement the entire process, put the processes that need to be executed in parallel into different threads, and continue the execution of subsequent processes after waiting for multiple threads to complete execution.

[0059] Solution 2: Create a different semaphore for each point that needs to be reached. After each process sets the semaphore corresponding to the current point to the signaled state, it waits for the signal of other processes at that point, and uses named signals at specific locations to achieve full arrival semantics.

[0060] For the above-mentioned solution 1: the parallel execution process requires the creation and execution waiting of multiple parallel process threads. Each additional synchronization point requires repeated thread creation. The more points that need to be reached, the more complex the program. For the single-threaded execution process that has been developed to be transformed into multi-process collaborative work, the workload of reconstructing multiple processes with many synchronization points is large.

[0061] For the second solution introduced above: a synchronization semaphore needs to be created for each process and each arrival point, and a semaphore needs to be created for each arrival point. For an indefinite number of synchronization processes and an indefinite number of arrival points, the implementation is complicated.

[0062] In view of the fact that most of the current multi-process synchronization solutions are difficult to adapt to complex and changeable business needs, this application studies a multi-process synchronization solution. When multiple processes need to be processed synchronously, the multi-process synchronization system provided by the embodiment of the present application can use a limited and determined number of semaphores, combined with the use of counts, to achieve a method of ensuring that an indefinite number of multi-processes continue to execute concurrently after executing concurrently to a specified position, and the multi-process synchronization system provided by the embodiment of the present application is not related to the position and number of times used for process synchronization. By completing the full arrival semantics of multiple running instances of a program or multiple different instances of multiple processes at the points where synchronization is required, multiple processes can be efficiently synchronized and processed synchronously, effectively reducing the complexity of concurrent execution system design.

[0063] The method provided in the embodiments of the present application can be used in many general or special computing device environments or configurations, such as personal computers, server computers, handheld devices or portable devices, tablet devices, multi-processor devices, etc.

[0064] The embodiment of the present application provides a multi-process synchronization system. The method can be applied to various process synchronization management systems, and can also be applied to various computer terminals or smart terminals. The execution subject can be a processor or server of the computer terminal or smart terminal.

[0065] Combine the following Figure 1 , introduces an optional system architecture provided in an embodiment of the present application that can achieve synchronization of multiple processes when they arrive at the synchronization position at the same time, such as Figure 1 As shown, the system architecture may include: an initialization interface, a join synchronization interface, a full reach synchronization interface, a rollback interface, and an exit synchronization interface.

[0066] In actual application, in order to ensure that the initial states of each process to be synchronized remain consistent and clear, it is possible to consider initializing each process to be synchronized before synchronizing it.

[0067] Initializing the processes to be synchronized can set the same initial conditions for each process to be synchronized, wherein the initialization conditions can include the initial values ​​of variables, the initial allocation of resources, etc., to avoid inconsistencies and errors in subsequent operations due to differences in the initial state; and initializing each process to be synchronized can help to effectively manage the resources of each process to be synchronized. In the initialization stage, the required system resources, such as memory, file descriptors, etc., can be reasonably allocated to each process to prevent resource competition and conflict. Further, initializing each process to be synchronized can establish a unified synchronization mechanism and rules. By initializing each process to be synchronized, the same initial values ​​and usage rules of synchronization tools such as synchronization semaphores and mutexes can be set for each process to be synchronized, so that each process to be synchronized can be synchronized and coordinated in a predetermined manner in subsequent collaboration. In addition, initializing each process to be synchronized can also effectively improve the predictability and stability of the system. After initialization, the behavior and performance of each process to be synchronized become more predictable to a certain extent, reducing the uncertainty and potential system crash risk caused by undefined or random initial states.

[0068] In summary, initializing multiple processes to be synchronized is of vital importance to ensuring the correct operation of the system, the rational allocation of resources, and improving the overall stability and predictability.

[0069] Therefore, the initialization interface provided in the embodiment of the present application can be responsible for initializing the fields of the process to be synchronized.

[0070] In actual application, the initialization interface provided in the embodiment of the present application mainly completes the resource application and initialization work before multi-process synchronization, and prepares for the subsequent multi-process synchronization.

[0071] The initialization interface is generally called in the first startup process to complete the application of shared storage space and process initialization. The shared storage space applied by the initialization interface is mainly used to store the running status fields of each process. Among them, the specific fields of the running status of each process are as follows:

[0072] 1. The bInit field indicates whether the process has joined the synchronization process. When the bInit of the process is initialized to 0, it means that the process has not yet joined the synchronization scope.

[0073] 2. The syncStep field can represent the process execution progress counter, which is initialized to 0;

[0074] 3. The rDepth field can represent the process rollback depth counter, which is initialized to 0;

[0075] 4. The waitNR field can indicate whether to wait until other processes joining the synchronization execute to this point again, and is initialized to 0.

[0076] Among them, the wait state parameter of the process, the process rollback depth counter, and the value of the process execution progress counter are usually related to the process wait queue.

[0077] The waiting state parameter indicates whether the current process waits until other processes continue to synchronize with other processes when the next round of execution reaches the current point.

[0078] The value of the process rollback depth counter indicates how many synchronization interfaces are reached by the rolled-back executed code.

[0079] The process execution progress counter records how many of the currently executed processes have executed and how many of them have reached the synchronization interface, that is, the execution progress of the system.

[0080] This status information can help the system identify the execution progress and rollback status of the process so as to perform corresponding scheduling and resource management.

[0081] For example, the shared memory allocation requested by the initialization interface can be as follows Figure 2 shown.

[0082] from Figure 2 It can be seen that each process has a variable that records the above four fields in the shared memory belonging to the process.

[0083] The initialization interface can complete the initialization action for all process fields, and the process can be as follows:

[0084] (1) The named semaphores requested by the initialization interface are equal to the square of the number of processes, and all the named semaphores requested are placed in a two-dimensional array, and each semaphore is initialized to a non-signaled state. A row of semaphores in the two-dimensional array corresponds to a semaphore used in the working process of a process, and the process can be mapped to each row of the two-dimensional array one by one according to the process number. To simplify the description of the two-dimensional array, the starting row and column numbers of the two-dimensional data can be written from 1, and the process number is also assigned from 1. The row corresponding to the process number is the semaphore operated by the process.

[0085] (2) Other startup processes use the initialization interface to complete access to the shared storage area without re-initializing the shared storage;

[0086] (3) Complete the acquisition of the kernel object matrix. When multiple processes access kernel objects, they need to create a process for other processes to use. The first process to be executed creates a semaphore. When other processes find that a semaphore has been created, they will directly obtain the created semaphore. Then, the semaphore is operated in each process space.

[0087] From the above introduction, it can be seen that the joining synchronization process flag of all processes to be synchronized is initialized to 0. In order to add each process to be synchronized to the scope to be synchronized, the joining synchronization interface provided in the embodiment of the present application can be responsible for setting the joining synchronization process flag of all processes to be synchronized to 1, so that all processes to be synchronized can be included in the process set to be synchronized, wherein the process set to be synchronized can include at least one process to be synchronized; after all processes to be synchronized are included in the scope to be synchronized, a multi-process synchronization process can be performed on them. Therefore, the all arrival synchronization interface provided in the embodiment of the present application can determine the synchronization position where all processes to be synchronized need to arrive; and at the synchronization position where all processes to be synchronized need to arrive, according to the preset synchronization strategy, multi-process synchronization is performed on all processes to be synchronized in the process set to be synchronized.

[0088] From this, we can see that multi-process point synchronization can be achieved by calling the all-arrival synchronization interface at the synchronization position that needs to be reached.

[0089] The processing logic of all arrival synchronization interfaces mainly includes the following aspects:

[0090] (1) Two synchronization logics;

[0091] (2) Normal test synchronization logic;

[0092] (3) Synchronization logic for process rollback;

[0093] (4) Update logic of process execution progress counter and process rollback depth counter;

[0094] (5) The semaphore is set to signal logic;

[0095] (6) Semaphore selection, waiting, and reset logic in the semaphore matrix.

[0096] The semaphore matrix provided in the embodiment of the present application is a square semaphore matrix, whose dimension is the number of processes, one dimension corresponds to the number of the running process, and the other dimension corresponds to the number of the notified process;

[0097] During the synchronization of the process, rollback is sometimes required. The main reasons include the following:

[0098] 1. Error recovery: When an error occurs in the code segment executed by the process between two synchronization points, rollback can restore the process state to a previous known correct point so that the synchronization operation can be retried, thereby improving the fault tolerance and reliability of the system.

[0099] 2. Avoid deadlock: In complex synchronization scenarios, processes may be deadlocked due to waiting for resources. By rolling back, you can break this stalemate, readjust the resource allocation strategy, and avoid deadlock.

[0100] 3. Conflict resolution: Conflicts may occur when multiple processes compete for shared resources at the same time. Rollback can return the conflicting processes to a suitable state and re-coordinate the order of resource access to achieve correct synchronization.

[0101] 4. Optimize performance: If the execution path of a synchronization operation is not optimal, rolling back and reselecting may improve the overall system performance.

[0102] In short, rollback processing is an important mechanism in process synchronization, which is used to deal with various abnormal situations and ensure the correct operation and performance optimization of the system.

[0103] Therefore, when synchronizing all processes to be synchronized, when process rollback is required, the rollback interface provided in the embodiment of the present application can set the value of the process rollback depth counter of the currently executing process to a preset first threshold, and set the value of the process execution progress counter of the currently executing process to a preset second threshold.

[0104] The preset first threshold value may be set to the number of all arriving synchronization interfaces spanned by the backoff;

[0105] The preset second threshold may be set to a difference between an original value of a process execution progress counter of a currently executed process and twice the preset first threshold.

[0106] For example, the rollback interface is mainly used in scenarios where the previous process needs to be executed repeatedly.

[0107] For example: in the execution process based on input from other devices, the subsequent process execution continues after a certain condition state is reached according to the information, otherwise jump to the previous process to re-execute the same job. When the repeated execution of the job contains an indefinite number of all arrival synchronizations, the rollback interface can be called to control the rollback processing of the process.

[0108] For example, the fallback interface input is the number of all arrival synchronization interfaces that are repeatedly called.

[0109] The implementation logic of the fallback interface is as follows:

[0110] When several processes are performing all-arrival synchronization processing, the value of the process execution depth counter can be set to the number of all-arrival synchronization interfaces crossed by the rollback to determine the rollback depth. At the same time, the value of the process execution progress counter is set to the current value of the process execution progress counter minus twice the value of the process depth counter.

[0111] Based on this, the all-arrival synchronization interface performs multi-process synchronization on all the processes to be synchronized in the process set to be synchronized at the synchronization position where all the processes to be synchronized need to arrive according to the preset synchronization strategy, including:

[0112] Step S101, checking whether the values ​​of the process execution progress counters of all the processes to be synchronized are 0 or 1 according to the synchronization positions that all the processes to be synchronized need to reach; if the values ​​of the process execution progress counters of all the processes to be synchronized are 0 or 1, executing step S102;

[0113] Step S102, restoring the waiting state parameter of the currently executed process whose process execution progress counter has a value of 0 or 1 and the value of the process rollback depth counter to 0;

[0114] Step S103, incrementing the value of the process execution progress counter of the currently executed process by 1, and if the value of the process rollback depth counter of the currently executed process is not 0, decrementing the value of the process rollback depth counter of the currently executed process by 1;

[0115] Step S104, setting the row corresponding to the process number of the currently executed process in the semaphore array to a signaled state;

[0116] Step S105, checking whether the waiting state parameter of the currently executed process is 0;

[0117] Step S106, if the waiting state parameter of the currently executed process is 0, then check whether there is a process whose process rollback depth counter value is not 0 among all the processes to be synchronized;

[0118] If there is no process whose process rollback depth counter value is non-0 among all the processes to be synchronized, step S109 is executed;

[0119] If there is a process whose process rollback depth counter value is non-0 among all the processes to be synchronized, step S115 is executed;

[0120] Step S107, if the waiting state parameter of the currently executed process is non-zero, then count the number of processes whose initialization state parameter is 1 and whose waiting state parameter is 0 among all the processes to be synchronized;

[0121] If the number of processes whose initialization state parameter is 1 and whose waiting state parameter is 0 among all the processes to be synchronized is 0, step S108 is executed.

[0122] Step S108, setting the synchronization state parameters of all processes to be synchronized to 0, and returning to execute step S105;

[0123] Step S109, determining the value corresponding to the process execution progress counter of the first target process whose process execution progress counter has the maximum value among all processes whose process rollback depth counters have the value of 0; and calculating the first difference between the value of the process execution progress counter of the currently executed process and the value corresponding to the process execution progress counter of the first target process;

[0124] Step S110, determining whether the first difference is less than -2;

[0125] If the first difference is less than -2, execute step S111; if the first difference is greater than -2, execute step S112;

[0126] Step S111, setting the waiting state parameter of the currently executed process to 1;

[0127] Step S112, in the column corresponding to the process number of the currently executed process in the semaphore array, the row index corresponding to the process number of the process whose difference between the process execution progress counter of all processes and the process execution progress counter of the first target process is greater than or equal to -2 is used to select the semaphore set for waiting;

[0128] Step S113, determining whether the waiting time of the current execution process exceeds a preset first time;

[0129] If the waiting time of the currently executed process does not exceed the preset first time, or if the first difference is equal to -2, execute step S114;

[0130] If the waiting time of the currently executed process exceeds the preset first time, the process returns to step S105;

[0131] Step S114, setting the column corresponding to the process number of the currently executed process in the semaphore array to a no-signal state, and incrementing the value of the process execution progress counter of the currently executed process by 1;

[0132] Step S115, determining whether the value of the process rollback depth counter of the currently executed process is non-zero;

[0133] If the value of the process rollback depth counter of the currently executed process is 0, the process returns to step S105;

[0134] If the value of the process rollback depth counter of the currently executed process is not 0, execute step S116;

[0135] Step S116, determine the value corresponding to the process rollback depth counter of the process whose process rollback depth counter has the maximum value among all the processes to be synchronized, and respectively calculate the second difference between the value of the process rollback depth counter of all the processes whose process rollback depth counters have non-zero values ​​and the value of the process rollback depth counter of the maximum value, and determine whether the value of the process rollback depth counter of the current process is the smallest and only value of the process rollback depth counter among all the processes to be synchronized;

[0136] If the value of the process rollback depth counter of the currently executed process is the smallest and only value of the process rollback depth counter of all processes to be synchronized, then the process returns to step S105;

[0137] If the value of the process rollback depth counter of the currently executed process is not the smallest and only value of the process rollback depth counter among all the processes to be synchronized, then execute step S117;

[0138] Step S117, determining a third difference between the value of the process rollback depth counter of the currently executed process and the value of the process rollback depth counter of the process whose process rollback depth counter value is the maximum value among all the processes to be synchronized; and subtracting the second difference value of each process other than the currently executed process among all the processes to be synchronized from the third difference value, respectively, to obtain a fourth difference between the second difference value of each process other than the currently executed process among all the processes to be synchronized and the third difference value;

[0139] Step S118, determine that the row of the fourth target process corresponding to the fourth difference value is less than or equal to 2 and the process number of the currently executed process are used as columns to index out the first semaphore set for waiting;

[0140] Step S119, determining whether the waiting time of the currently executed process for the first semaphore set exceeds a preset second time length;

[0141] If the waiting time of the currently executed process for the first semaphore set does not exceed the preset second time length, step S120 is executed;

[0142] If the currently executed process waits for the first semaphore set for more than the preset second time period, the process returns to step S105.

[0143] Step S120, setting the row corresponding to the process number of the currently executed process in the semaphore array to a no-signal state, and decrementing the value of the process execution progress counter of the currently executed process by 1.

[0144] in,

[0145] The preset first duration and the preset second duration are set according to the process synchronization test scenario requirements. For example, the range of the preset first duration and the preset second duration can both be set to [500ms-2s].

[0146] In actual application, when all processes to be synchronized have completed synchronization and no further process synchronization is required, the exit synchronization interface provided in the embodiment of the present application can restore the currently executing process to the initial state, set the waiting state parameters of all processes to 0, and set all signals in the index row of the currently executing process in the signal matrix to a no-signal state.

[0147] For example, when process synchronization is not required, the Exit Synchronization interface can be called to disable synchronization. After calling the Exit Synchronization interface, calling the All Arrival Synchronization interface will not trigger the synchronization process. The implementation logic of the Exit Synchronization interface can be as follows:

[0148] Restore the common variables of the currently executing process to their initial state, that is, set the value of the synchronization process flag, the value of the process execution depth counter, and the value of the process rollback depth counter to 0, set the waiting state parameter of the currently executing process to 0, and set all signals in the index row of the current process number in the signal matrix to a no-signal state.

[0149] For example, Figure 3 An example of an implementation logic diagram of the all-arrival synchronization interface provided in an embodiment of the present application is provided.

[0150] like Figure 3 As shown, the specific steps can be as follows:

[0151] S1, check whether the syncStep (process execution progress counter) value of all processes is 0 or 1. If there is a process whose syncStep value is 0 or 1, restore the waitNR (wait state parameter) state of the process to 0;

[0152] S2, the value of the current process syncStep is incremented by 1, and if the value of the rDepth of the currently executed process is not 0, it is decremented by 1;

[0153] S3, set the behavior corresponding to the process number of the current process in the semaphore array to have a signal state;

[0154] S4, check whether the currently executed process waiteNR is 0;

[0155] S5, if the waitNR of the currently executed process is 0, check whether the rDepth value of all processes is not 0;

[0156] S6, if the waitNR of the currently executed process is not 0, count the number of processes with iInitialized=1 and waitNR=0. If the number of processes with iInitialized=1 and waitNR=0 is 0, set the waitNR of all processes to 0 and return to execute S4;

[0157] S7, if there is no process with a non-zero rDepth value among all processes, determine that the syncStep value of the process with a non-zero rDepth value is the maximum value (syncStepMax); if there is a process with a non-zero rDepth value among all processes, execute S14;

[0158] S8, calculating the difference stepDiff between the syncStep value of the currently executed process and syncStepMax;

[0159] S9, if the difference stepDiff between the syncStep value of the currently executed process and syncStepMax is less than -2, then set the waitNR of the currently executed process to 1;

[0160] S10, if the difference stepDiff between the syncStep value of the currently executed process and syncStepMax is greater than -2, then in the column corresponding to the current process number of the semaphore array, the syncStep of all processes is subtracted from the syncStepMax, and the row index corresponding to the process number of the process with the difference greater than or equal to -2 is taken to wait in semaphore set 1;

[0161] S11, determine whether the currently executed process has timed out waiting for semaphore set 1 (the timeout period is generally set to 500ms to 2s);

[0162] S12, if the currently executed process does not time out when waiting for the semaphore set 1, or if the difference stepDiff between the syncStep value of the currently executed process and syncStepMax is equal to -2, then set the column corresponding to the process number in the semaphore array to a no-signal state; and increment the syncStep value of the currently executed process by 1.

[0163] Step S13, if the currently executed process times out waiting for semaphore set 1, step S4 is executed again;

[0164] Step S14, if the value of rDepth0 of the currently executed process is 0, return to execute step S4; if the value of rDepth of the currently executed process is not 0, determine the maximum rDepth value rDepthMax of all values, and calculate the difference rDepthdiff between all processes with non-0 rDepth values ​​and rDepthMax;

[0165] S15, determine whether the value of rDepth of the currently executed process is the smallest and unique, if so, return to execute step S4, otherwise continue with the subsequent steps;

[0166] S16, if the value of rDepth of the currently executed process is not the smallest, then the difference between the rDepthDiff of other processes and the rDepthDiff of the current process is taken, and in the column corresponding to the process number of the currently executed process in the semaphore array, the row corresponding to the process number of the process whose difference between the two is less than or equal to 2 is taken and the column corresponding to the process number of the currently executed process is indexed to obtain the semaphore set 2 for waiting;

[0167] S17, determining whether the waiting time of the currently executed process for the semaphore set 2 has timed out;

[0168] S18, if the waiting time of the currently executed process for the semaphore set 2 does not time out, then set the column corresponding to the process number in the semaphore array to a no-signal state, and decrement the value of the current process rDepth by 1;

[0169] S19: If the waiting time of the currently executed process for the semaphore set 2 times out, return to step S4.

[0170] For example, Figure 4 This example illustrates the process of all processes arriving at synchronization. Figure 4 As shown;

[0171] Step S301, the executed process completes the creation and initialization of the shared storage space of N*N semaphores, and other processes only complete the access action.

[0172] Step S302: the codes executed by each process may be the same or different.

[0173] After all processes have completed step S303, they will concurrently execute phase 1. When all processes have executed step S304, they will continue to concurrently execute the next phase code, and all subsequent programs will be executed in parallel by phase. If other processes have completed step S303, but some processes have failed to complete step S302, the programs that have failed to complete the execution will be blocked at step S303 until all the programs that have completed step S303 have completed the exit synchronization interface.

[0174] When the execution reaches the k+1 stage, Figure 4 As shown, there is a fallback condition in process 1 (process 1 is only an example, and the fallback condition can occur in any process). If the fallback condition is met, the fallback process will be executed, and other processes will be blocked to the synchronization interface where the k+1 stage is executed until process 1 executes step S305 again, and all processes continue to execute subsequent processes concurrently.

[0175] In particular, for process N, since the exit synchronization interface has been called before step S307, the step S307 stage will not wait for all other processes to arrive, and the subsequent code execution can continue independently.

[0176] It can be seen from the technical solution introduced above that when multiple processes need to be synchronized at the same synchronous arrival synchronization position, the multi-process synchronization system provided by the embodiment of the present application can use a limited and determined number of semaphores, and use counting to achieve a method of ensuring that an indefinite number of multi-processes are executed concurrently to a specified position and then continue to execute concurrently, and the multi-process synchronization system provided by the embodiment of the present application is not related to the position used by the process synchronization and the number of times used. By adding the simultaneous arrival synchronization interface at the point where synchronization is required, the effect of all arrival semantics of multiple running instances of a program or multiple different instances of multiple processes can be completed, and multiple processes can be efficiently synchronized for synchronization, effectively reducing the implementation complexity of the multi-point synchronization system. Further, the system provided by the embodiment of the present application can be used as a program framework to facilitate the implementation of the subsequent code flow after all processes have arrived at any set point, and it has universality. The user only needs to complete the initialization interface and add the synchronization interface in multiple processes that need to work together, and add the synchronization interface call at the point where all need to arrive, and a process can use the exit synchronization interface at any time to realize the independent operation of the subsequent process, and the single process flow is not affected. For any process that has been developed, a small modification can be made to achieve collaborative work. At the same time, this method supports the execution process rollback function, which expands the application scope of the synchronization system.

[0177] It can be seen from this that the multi-process synchronization system provided by the embodiment of the present application can determine the program running progress by incrementing the count before and after the synchronization waiting logic, and can select multiple signals that need to be waited for from the semaphore matrix by comparing the difference between the current process running count and the running counts of each process, and implement the correct backoff logic by updating the process running counter and the backoff step counter. In addition, when the difference between the current process running count and the running counts of other active processes is greater than 2 and the current count value is 1, combined with the whether to retry attribute, it is determined whether the current process needs to wait for the next round of testing to start.

[0178] The multi-process synchronization system provided in the embodiment of the present application can be applied to multi-process synchronization devices, such as terminals: mobile phones, computers, etc. Optionally, Figure 5 The hardware structure diagram of the multi-process synchronization device is shown in FIG. Figure 5 The hardware structure of the multi-process synchronization device may include: at least one processor 1, at least one communication interface 2, at least one memory 3 and at least one communication bus 4.

[0179] In the embodiment of the present application, the number of the processor 1 , the communication interface 2 , the memory 3 , and the communication bus 4 is at least one, and the processor 1 , the communication interface 2 , and the memory 3 communicate with each other through the communication bus 4 .

[0180] The processor 1 may be a central processing unit CPU, or an application-specific integrated circuit ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present application, etc.;

[0181] The memory 3 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory;

[0182] The memory stores a program, and the processor can call the program stored in the memory, wherein the program is used to implement each processing flow in the aforementioned terminal multi-process synchronization solution.

[0183] An embodiment of the present application further provides a readable storage medium, which can store a program suitable for execution by a processor, wherein the program is used to: implement various processing flows of the aforementioned terminal in a multi-process synchronization solution.

[0184] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0185] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0186] The above description of the disclosed embodiments enables professionals and technicians in the field to implement or use the present application. Various modifications to these embodiments will be apparent to professionals and technicians in the field, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. The various embodiments can be combined with each other. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A multi-process synchronization system, characterized in that: include: Initialize interface, join synchronization interface, and all arrive at synchronization interface; The initialization is responsible for initializing the fields of the process to be synchronized; The join synchronization interface is responsible for setting the join synchronization process flags of all processes to be synchronized to 1, so as to include all processes to be synchronized into a set of processes to be synchronized, wherein the set of processes to be synchronized includes at least one process to be synchronized; The all-arrival synchronization interface is responsible for determining the synchronization position to which all processes to be synchronized need to arrive; And at the synchronization position where all the processes to be synchronized need to reach, multi-process synchronization is performed on all the processes to be synchronized in the set of processes to be synchronized according to a preset synchronization strategy.

2. The system according to claim 1, characterized in that The system also includes a fallback interface; When a process rollback is required, the rollback interface is responsible for setting the value of the process rollback depth counter of the currently executed process to a preset first threshold, and setting the value of the process execution progress counter of the currently executed process to a preset second threshold; Wherein, the preset first threshold is set to the number of all arrival synchronization interfaces spanned by the backoff; The preset second threshold is set as the difference between the original value of the process execution progress counter of the currently executed process and twice the preset first threshold.

3. The system according to claim 2, characterized in that The process of performing multi-process synchronization on all the processes to be synchronized in the set of processes to be synchronized according to a preset synchronization strategy at the synchronization position where all the processes to be synchronized need to arrive at by the all-arrived synchronization interface includes: According to the synchronization position that all the processes to be synchronized need to reach, check whether the values ​​of the process execution progress counters of all the processes to be synchronized are 0 or 1; If the values ​​of the process execution progress counters in all the processes to be synchronized are 0 or 1, the waiting state parameter of the currently executed process is restored to 0; Increment the value of the process execution progress counter of the currently executed process by 1. If the value of the process rollback depth counter of the currently executed process is non-zero, decrement the value of the process rollback depth counter of the currently executed process by 1. Set the row corresponding to the process number of the currently executing process in the semaphore array to the signaled state; Check whether the wait state parameter of the currently executed process is 0; If the wait state parameter of the currently executed process is 0, check whether there is a process whose process rollback depth counter value is not 0 among all the processes to be synchronized; If the wait state parameter of the currently executed process is non-zero, then count the number of processes whose initialization state parameter is 1 and whose wait state parameter is 0 among all the processes to be synchronized; If the number of processes whose initialization state parameter is 1 and whose waiting state parameter is 0 among all the processes to be synchronized is 0, the waiting state parameters of all the processes to be synchronized are set to 0, and the operation of checking whether the waiting state parameter of the currently executed process is 0 is returned; If there is no process whose process rollback depth counter value is non-0 among all the processes to be synchronized, non-rollback processing is performed, and the value of the process execution progress counter of the currently executed process is incremented by 1; If there is a process whose process rollback depth counter value is non-0 among all the processes to be synchronized, then determine whether the value of the process rollback depth counter of the currently executed process is non-0; If the value of the process rollback depth counter of the currently executed process is 0, the operation of checking whether the wait state parameter of the currently executed process is 0 is returned to be executed.

4. The system according to claim 3, characterized in that The non-rollback process includes: Determine the value corresponding to the process execution progress counter of the first target process whose process execution progress counter has the maximum value among all processes whose process rollback depth counters have the value of 0; and calculate the first difference between the value of the process execution progress counter of the currently executed process and the value of the process execution progress counter of the first target process; Determine whether the first difference is less than -2; If the first difference is less than -2, the waiting state parameter of the currently executing process is set to 1; If the first difference is greater than -2, in the column corresponding to the process number of the currently executed process in the semaphore array, the row indexes corresponding to the process numbers of all processes whose first difference is greater than -2 are used to select the semaphore set for waiting; Determine whether the waiting time of the currently executed process exceeds a preset first time length; If the waiting time of the currently executed process does not exceed the preset first time, the column corresponding to the process number of the currently executed process in the semaphore array is set to a no-signal state; If the waiting time of the currently executed process exceeds the preset first time, returning to execute the operation of checking whether the waiting state parameter of the currently executed process is 0; If the first difference is equal to -2, the column corresponding to the process number of the currently executed process in the semaphore array is set to a no-signal state.

5. The system according to claim 3, characterized in that If the value of the process rollback depth counter of the currently executed process is not 0, the process rollback processing is performed.

6. The system according to claim 5, characterized in that The non-rollback process includes: Determine the value of the process rollback depth counter of the process whose process rollback depth counter has the maximum value among all the processes to be synchronized, and respectively calculate the second difference between the value of the process rollback depth counter of all the processes whose process rollback depth counters have non-zero values ​​and the value of the process rollback depth counter of the maximum value, and return the step of determining whether the value of the process rollback depth counter of the current process is the minimum and only value of the process rollback depth counter among all the processes to be synchronized; If the value of the process rollback depth counter of the currently executed process is the smallest and only value of the process rollback depth counter among all the processes to be synchronized, then return to execute the operation of checking whether the wait state parameter of the currently executed process is 0; If the value of the process rollback depth counter of the currently executed process is not the smallest and only value of the process rollback depth counter among all the processes to be synchronized, then determine the third difference between the value of the process rollback depth counter of the currently executed process and the value of the process rollback depth counter of the process whose process rollback depth counter value is the maximum value among all the processes to be synchronized; and subtract the second difference value of each process other than the currently executed process among all the processes to be synchronized from the third difference value, respectively, to obtain a fourth difference between the second difference value of each process other than the currently executed process among all the processes to be synchronized; Determine that the rows corresponding to the process numbers of all processes corresponding to the fourth difference being less than or equal to 2 and the columns corresponding to the process number of the currently executed process are indexed to extract the first semaphore set for waiting; Determine whether the waiting time of the currently executed process for the first semaphore set exceeds a preset second time length; If the waiting time of the currently executed process for the first semaphore set does not exceed the preset second time length, the column corresponding to the process number of the currently executed process in the semaphore array is set to a no-signal state, and the value of the process execution progress counter of the currently executed process is decremented by 1; If the waiting time of the currently executed process for the first semaphore set exceeds the preset second time length, the operation of checking whether the waiting state parameter of the currently executed process is 0 is returned to be executed.

7. The system according to claim 1, characterized in that The system also includes an exit synchronization interface; When all processes to be synchronized have completed synchronization and no further process synchronization is required, the exit synchronization interface is responsible for restoring the currently executing process to the initial state, setting the waiting state parameters of all processes to 0, and setting all signals in the index row of the currently executing process in the signal matrix to a no-signal state.

8. The system according to claim 4 or 5, characterized in that: The preset first duration and the preset second duration are set according to the process synchronization test scenario requirements.

9. A multi-process synchronization device, characterized in that: include: one or more processors, and memory; The memory stores computer-readable instructions, which, when executed by the one or more processors, implement the execution steps of the multi-process synchronization system as claimed in any one of claims 1 to 8.

10. A readable storage medium, characterized in that: The readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by one or more processors, the one or more processors implement the execution steps of the multi-process synchronization system as claimed in any one of claims 1 to 8.