Master-slave task state synchronization method and device based on lock and time signal

CN120803760BActive Publication Date: 2026-09-22SHANDONG YOU INTERNET OF THINGS CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510959999.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-07-11
Publication Date
2026-09-22
Estimated Expiration
2045-07-11

AI Technical Summary

Technical Problem

[0004]主任务和从任务都有状态,主任务的状态只有在从任务均完成时,主任务才会标记为完成,而从任务是以并发的方式执行,而主任务查看所有子任务是否完成的时机是目前的技术难点:若主任务查看子任务太频繁,也就是轮询太频繁,会影响SIM连接平台的性能,造成性能开销大的问题;若主任务查看子任务的次数太少,也就是轮询太稀疏,可能会出现两个层级状态不同步以及可能错过查看子任务完成得时机的问题

Benefits of technology

本发明利用插件形式安装主状态执行器,对主从本身的业务逻辑无侵入;而且利用主状态执行锁抵御流量洪峰,确保前面有很多从任务需要执行后续主任务时,后续只释放1个主任务进行下去,节省了应用线程资源和数据库的计算资源;利用主状态最早执行时间信号记录器记录时间完成主任务的延迟操作,让主任务不频繁启动和销毁,节省了应用线程资源和数据库的计算资源,实现了主从任务的低延迟同步状态、高性能同步状态及有需再唤醒同步状态。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120803760B_ABST
    Figure CN120803760B_ABST
Patent Text Reader

Abstract

The application belongs to the field of data processing, and provides a master-slave task state synchronization method and device based on a lock and a time signal. The method comprises the following steps: connecting a master state executor in the form of a plug-in between a master task and a slave task; executing all slave tasks concurrently, and submitting a transaction after each slave task is completed, and then calling the master state executor; resetting the time in a master state earliest execution time signal recorder to the current time plus a set time; judging whether the master state execution lock is successfully locked, and if not, ending the master state executor; when the master state execution lock is successfully locked, judging whether the current time is not later than the time recorded in the master state earliest execution time signal recorder, and if so, the master state executor delays for a set time and then judges again, otherwise, the master state execution lock is unlocked; judging whether all slave tasks have been completed, and if so, changing the master task state to completed, and ending the master state executor, otherwise, directly ending the master state executor.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of data processing, and particularly relates to a master-slave task state synchronization method and apparatus based on locks and time signals. Background Technology

[0002] The statements in this section are merely background information related to the present invention and do not necessarily constitute prior art.

[0003] The SIM connectivity platform contains a large number of tasks of different types, which are divided into two levels: main tasks and secondary tasks. The main tasks summarize and aggregate information, while the secondary tasks record in detail the various information required for processing. The relationship between the main tasks and secondary tasks is one to many.

[0004] Both the main task and the slave tasks have states. The main task is only marked as completed when all slave tasks are completed. Slave tasks are executed concurrently. The timing of when the main task checks whether all subtasks are completed is a current technical challenge: if the main task checks the subtasks too frequently, that is, polls too frequently, it will affect the performance of the SIM connection platform and cause a large performance overhead; if the main task checks the subtasks too infrequently, that is, polls too sparsely, there may be a lack of synchronization between the two levels of states and the opportunity to check the completion of subtasks may be missed. Summary of the Invention

[0005] To address the technical problems existing in the background art, the present invention provides a master-slave task state synchronization method and apparatus based on locks and time signals, which can achieve low-latency synchronization and high-performance synchronization of master and slave tasks.

[0006] To achieve the above objectives, the present invention adopts the following technical solution: The first aspect of the present invention provides a master-slave task state synchronization method based on locks and time signals.

[0007] A master-slave task state synchronization method based on locks and time signals includes: Connect the master state executor between the master task and the slave task as a plug-in; All slave tasks are executed concurrently. After each slave task is completed, the transaction is committed first, and then the master state executor is called. Reset the time in the earliest execution time signal recorder of the main state to the current time plus the set time; Determine whether the lock was successfully acquired in the main state execution. If it fails, terminate the main state executor. When the main state execution lock is successfully locked, it is determined whether the current time is not later than the time recorded in the earliest execution time signal recorder of the main state. If so, the main state executor delays for a set time and then determines whether the current time is not later than the time recorded in the earliest execution time signal recorder of the main state. Otherwise, the main state execution lock is unlocked. Determine if all slave tasks have been completed. If so, change the main task status to completed and terminate the main state executor; otherwise, terminate the main state executor directly.

[0008] As one implementation, a first space and a second space are allocated in the memory of the main state executor to store the default real-time value and the state representing the main state execution lock, respectively.

[0009] As one implementation method, the value in the second space is 0 by default, which means unlocked; when the value in the second space is 1, it means locked.

[0010] As one implementation method, the main state execution lock is determined to be successfully locked based on the values ​​in the first space and the second space.

[0011] As one implementation method, the conditions for successful locking in the main state are: When the value in the second space is 0 and the value in the first space is the same as the value taken from the first space before the task, the value in the first space will be overwritten with a custom random value from the task.

[0012] As one implementation, a third space is allocated in the memory of the main state executor to store the time recorded by the earliest execution time signal recorder of the main state.

[0013] A second aspect of the present invention provides a master-slave task state synchronization device based on locks and time signals.

[0014] A master-slave task state synchronization device based on locks and time signals, comprising: The plug-in access module is used to connect the master state executor to the master task and the slave task in the form of a plug-in. The main state executor calling module is used to concurrently execute all slave tasks. After each slave task is completed, the transaction is committed first, and then the main state executor is called. The time reset module is used to reset the time in the earliest execution time signal recorder of the main state to the current time plus the set time; The lock acquisition success determination module is used to determine whether the lock acquisition in the main state execution is successful. If it fails, the main state executor will terminate. The time comparison module is used to determine whether the current time is not later than the time recorded in the earliest execution time signal recorder of the main state when the main state execution lock is successfully locked. If so, the main state executor will delay for a set time and then determine whether the current time is not later than the time recorded in the earliest execution time signal recorder of the main state. Otherwise, the main state execution lock will be unlocked. The task completion judgment module is used to determine whether all slave tasks have been completed. If so, the main task status is changed to completed and the main state executor is terminated; otherwise, the main state executor is terminated directly.

[0015] A third aspect of the present invention provides a computer-readable storage medium.

[0016] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the master-slave task state synchronization method based on locks and time signals as described above.

[0017] A fourth aspect of the present invention provides a computer program product.

[0018] A computer program product includes a computer program / instructions that, when executed by a processor, implement the steps in the master-slave task state synchronization method based on locks and time signals as described above.

[0019] A fifth aspect of the present invention provides an electronic device.

[0020] An electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the steps in the master-slave task state synchronization method based on locks and time signals as described above.

[0021] Compared with the prior art, the beneficial effects of the present invention are: This invention utilizes a plug-in approach to install the master state executor, without intruding on the business logic of the master and slave tasks themselves. Furthermore, it employs a master state execution lock to mitigate traffic surges, ensuring that when many slave tasks need to execute subsequent master tasks, only one master task is released to continue, saving application thread resources and database computing resources. By using a master state earliest execution time signal logger to record the time for delayed master task operations, the invention prevents frequent start-up and destruction of master tasks, further saving application thread resources and database computing resources. This achieves low-latency synchronization, high-performance synchronization, and re-wake-up synchronization states for master and slave tasks.

[0022] Advantages of additional aspects of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description

[0023] The accompanying drawings, which form part of this invention, are used to provide a further understanding of the invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an improper limitation of the invention.

[0024] Figure 1 This is a flowchart of a master-slave task state synchronization method based on locks and time signals according to an embodiment of the present invention; Figure 2 This is a diagram illustrating the implementation process of master-slave task state synchronization based on locks and time signals according to an embodiment of the present invention. Figure 3 This is a schematic diagram of a master-slave task state synchronization device based on locks and time signals according to an embodiment of the present invention. Detailed Implementation

[0025] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0026] It should be noted that the following detailed description is illustrative and intended to provide further explanation of the invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.

[0027] It should be noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of exemplary embodiments according to the invention. As used herein, the singular form is intended to include the plural form as well, unless the context clearly indicates otherwise. Furthermore, it should be understood that when the terms "comprising" and / or "including" are used in this specification, they indicate the presence of features, steps, operations, devices, components, and / or combinations thereof.

[0028] Terminology Explanation: A SIM connectivity platform is a platform used to manage and connect SIM cards, primarily for the management and communication of Internet of Things (IoT) devices. These platforms offer a range of functions, including device access, data transmission, remote control, and secure communication, helping businesses and developers manage and use SIM cards more effectively.

[0029] In this embodiment of the invention, the effect of waking up the synchronization state when necessary can be achieved. Specifically, when one or more subtasks have just completed, the system marks the main task state as "may need synchronization". Each time a subtask completes, a "wake-up signal" is set to tell the executor: "The main task state should be checked now". This ensures that the main task is only attempted to synchronize when it is truly necessary, avoiding meaningless waste.

[0030] Example 1 according to Figure 1 and Figure 2This invention provides a master-slave task state synchronization method based on locks and time signals, including: S101: Connect the master state executor as a plug-in between the master task and the slave task.

[0031] The master state executor is installed as a plug-in, which does not intrude on the business logic of the master and slave tasks themselves, and facilitates integration and debugging.

[0032] S102: Execute all slave tasks concurrently. After each slave task is completed, commit the transaction first, and then call the master state executor.

[0033] It should be noted here that both the concurrent slave tasks and the master state executor run in child processes.

[0034] In the specific implementation process, a first space and a second space are allocated in the memory of the main state executor to store the default random value and the state representing the main state execution lock, respectively.

[0035] The first space stores a random value by default.

[0036] The default value in the second space is 0, which means unlocked; a value of 1 in the second space means locked.

[0037] S103: Reset the time in the earliest execution time signal recorder of the main state to the current time plus a set time (e.g., 1 second, which can be set according to the actual situation).

[0038] A third space is allocated in the memory of the main state executor to store the time recorded by the earliest execution time signal logger of the main state. This third space can store a value for a certain period. Tasks can continuously update the value in this memory space. The main state executor listens to this space field to prevent its thread from being destroyed or releasing locks, thus maintaining its running state.

[0039] Therefore, the main state executor has a first space, a second space, and a third space in its memory, and also includes a delay and a listener.

[0040] Among them, the earliest execution time signal recorder of the main state completes the delayed operation of the main task by recording the time, so that the main task is not frequently started and destroyed, saving application thread resources and database computing resources.

[0041] S104: Determine whether the main state execution lock was successfully acquired. If it fails, terminate the main state executor.

[0042] The main state execution lock is determined to have been successfully locked based on the values ​​in the first and second spaces.

[0043] As one implementation method, the conditions for successful locking in the main state are: When the value in the second space is 0 and the value in the first space is the same as the value taken from the first space before the task, the value in the first space will be overwritten with a custom random value from the task.

[0044] The locking process is as follows: First, obtain the random value of the first space of the main state executor, and at the same time, also define a random value from the task itself. The update logic is that when the second space is 0 and the value of the first space is the same as the value of the first space that it previously retrieved, the value of the first space is overwritten with its own custom random value, and the second space is set to 1.

[0045] The unlocking process involves setting the second space to 0.

[0046] The purpose of the main state execution lock is to resist traffic surges and ensure that when there are many slave tasks that need to execute subsequent main tasks, only one main task is released to continue, thus saving application thread resources and database computing resources.

[0047] S105: When the main state execution lock is successfully locked, determine whether the current time is not later than the time recorded in the earliest execution time signal recorder of the main state. If so, the main state executor delays for a set time and then determines whether the current time is not later than the time recorded in the earliest execution time signal recorder of the main state. Otherwise, the main state execution lock is unlocked.

[0048] In this embodiment, the main state does not need to make a judgment when locking, which avoids the problem of checking whether to lock before locking, which may result in concurrent locking judgments and thus go undetected.

[0049] The main task's business logic is executed only after the lock is unlocked in the main state, thus avoiding the problem of being missed if a new main task enters during the unlocking process.

[0050] S106: Determine whether all slave tasks have been completed. If so, change the status of the master task to completed and terminate the master state executor; otherwise, terminate the master state executor directly.

[0051] For example, the master task table (master_tasks): task_id | status| created_at --------+-----------+--------------------- 1| PENDING| 2025-06-27 10:00:00; 2| PENDING| 2025-06-27 10:05:00; From the task table (slave_tasks): id | master_task_id | status| finished_at ---+----------------+------------+--------------------- 1| 1| COMPLETED| 2025-06-27 10:10:05; 2| 1| COMPLETED| 2025-06-27 10:11:00; 3| 1| COMPLETED| 2025-06-27 10:12:30; 4| 2| COMPLETED| 2025-06-27 10:15:00; 5| 2| PENDING| 2025-06-27 10:15:00; Main Task 1 has three sub-tasks, all of which have been completed; Main Task 2 has one sub-task completed and one sub-task incomplete.

[0052] After processing, it becomes: task_id | status| created_at --------+------------+--------------------- 1| COMPLETED| 2025-06-27 10:00:00; 2| PENDING| 2025-06-27 10:05:00; This shows that main task 1 is marked as completed.

[0053] This embodiment uses a plug-in approach to install the master state executor, which does not intrude on the business logic of the master and slave tasks themselves. Moreover, it uses a master state execution lock to resist traffic surges, ensuring that when many slave tasks need to execute subsequent master tasks, only one master task is released to continue, saving application thread resources and database computing resources. It uses the earliest execution time signal logger of the master state to record the time to complete the delayed operation of the master task, so that the master task is not frequently started and destroyed, saving application thread resources and database computing resources. It realizes the low-latency synchronization state, high-performance synchronization state, and synchronization state that needs to be woken up again for master and slave tasks.

[0054] Example 2 according to Figure 3 This paper provides a master-slave task state synchronization device based on locks and time signals, which specifically includes the following modules: The plug-in access module 301 is used to connect the master state executor between the master task and the slave task in the form of a plug-in. The master state executor calls module 302, which is used to concurrently execute all slave tasks. After each slave task is completed, it first commits the transaction and then calls the master state executor. The time reset module 303 is used to reset the time in the earliest execution time signal recorder of the main state to the current time plus the set time. The locking success determination module 304 is used to determine whether the main state execution lock has been successfully locked. If it fails, the main state executor will be terminated. The time comparison module 305 is used to determine whether the current time is not later than the time recorded in the earliest execution time signal recorder of the main state when the main state execution lock is successfully locked. If so, the main state executor will delay for a set time and then determine whether the current time is not later than the time recorded in the earliest execution time signal recorder of the main state. Otherwise, the main state execution lock will be unlocked. The task completion judgment module 306 is used to determine whether all slave tasks have been completed. If so, the main task status is changed to completed and the main state executor is terminated; otherwise, the main state executor is terminated directly.

[0055] It should be noted that each module in this embodiment corresponds one-to-one with each step in Embodiment 1 above, and their specific implementation process is the same, so it will not be repeated here.

[0056] Example 3 This embodiment provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps in the master-slave task state synchronization method based on locks and time signals as described above.

[0057] Example 4 A computer program product includes a computer program / instructions that, when executed by a processor, implement the steps in the master-slave task state synchronization method based on locks and time signals as described above.

[0058] Example 5 This embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the steps of the master-slave task state synchronization method based on locks and time signals as described above.

[0059] The electronic device in this embodiment includes a central processing unit (CPU), which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) or a program loaded from a storage portion into random access memory (RAM). The RAM also stores various programs and data required for system operation. The CPU, ROM, and RAM are interconnected via a bus. Input / output (I / O) interfaces are also connected to the bus.

[0060] The following components are connected to the I / O interface: input sections including keyboards, mice, etc.; output sections including cathode ray tubes (CRTs), liquid crystal displays (LCDs), and speakers; storage sections including hard disks; and communication sections including network interface cards such as local area network (LAN) cards and modems. The communication sections perform communication processing via networks such as the Internet. Drives are also connected to the I / O interface as needed. Removable media, such as disks, optical disks, magneto-optical disks, semiconductor memories, etc., are installed on the drive as needed so that computer programs read from them can be installed into the storage section as required.

[0061] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication component, and / or installed from a removable medium. When the computer program is executed by a central processing unit, it performs the various functions defined in the apparatus of this application.

[0062] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, as well as combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0063] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A master-slave task state synchronization method based on locks and time signals, characterized in that, include: Connect the master state executor between the master task and the slave task as a plug-in; All slave tasks are executed concurrently. After each slave task is completed, the transaction is committed first, and then the master state executor is called. Reset the time in the earliest execution time signal recorder of the main state to the current time plus the set time; Determine whether the lock was successfully acquired in the main state execution. If it fails, terminate the main state executor. When the main state execution lock is successfully locked, it is determined whether the current time is not later than the time recorded in the earliest execution time signal recorder of the main state. If so, the main state executor delays for a set time and then determines whether the current time is not later than the time recorded in the earliest execution time signal recorder of the main state. Otherwise, the main state execution lock is unlocked. Determine if all slave tasks have been completed. If so, change the main task status to completed and terminate the main state executor; otherwise, terminate the main state executor directly. In the memory of the main state executor, allocate a first space and a second space to store the default value and the state representing the main state execution lock, respectively. The condition for successfully locking the main state is: when the value in the second space is 0 and the value in the first space is the same as the value in the first space retrieved from the task, the value in the first space is overwritten with a user-defined random value from the task. A third space is also allocated in the memory of the main state executor to store the time recorded by the earliest execution time signal recorder of the main state.

2. The master-slave task state synchronization method based on locks and time signals as described in claim 1, characterized in that, The default value in the second space is 0, which means it is not locked. A value of 1 in the second space indicates that the device is locked.

3. The master-slave task state synchronization method based on locks and time signals as described in claim 1, characterized in that, The main state execution lock is determined to have been successfully locked based on the values ​​in the first and second spaces.

4. A master-slave task state synchronization device based on locks and time signals, characterized in that, include: The plug-in access module is used to connect the master state executor to the master task and the slave task in the form of a plug-in. The main state executor calling module is used to concurrently execute all slave tasks. After each slave task is completed, the transaction is committed first, and then the main state executor is called. The time reset module is used to reset the time in the earliest execution time signal recorder of the main state to the current time plus the set time; The lock acquisition success determination module is used to determine whether the lock acquisition in the main state execution is successful. If it fails, the main state executor will be terminated. The time comparison module is used to determine whether the current time is not later than the time recorded in the earliest execution time signal recorder of the main state when the main state execution lock is successfully locked. If so, the main state executor will delay for a set time and then determine whether the current time is not later than the time recorded in the earliest execution time signal recorder of the main state. Otherwise, the main state execution lock will be unlocked. The task completion judgment module is used to determine whether all slave tasks have been completed. If so, the main task status is changed to completed and the main state executor is terminated; otherwise, the main state executor is terminated directly. In the memory of the main state executor, allocate a first space and a second space to store the default value and the state representing the main state execution lock, respectively. The condition for successfully locking the main state is: when the value in the second space is 0 and the value in the first space is the same as the value in the first space retrieved from the task, the value in the first space is overwritten with a user-defined random value from the task. A third space is also allocated in the memory of the main state executor to store the time recorded by the earliest execution time signal recorder of the main state.

5. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the steps in the master-slave task state synchronization method based on locks and time signals as described in any one of claims 1-3.

6. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instruction is executed by the processor, it implements the steps in the master-slave task state synchronization method based on locks and time signals as described in any one of claims 1-3.

7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps in the master-slave task state synchronization method based on locks and time signals as described in any one of claims 1-3.

Citation Information

Patent Citations

  • Data processing method and device, electronic equipment and storage medium

    CN120104643A

  • Computer-implemented method of distributed management of locks, apparatus for distributed management of locks and computer program product

    CN120112894A