Robot multi-task cooperative synchronization method and device, equipment and medium

By dynamically constructing a synchronization point structure and a task counting mechanism, the problems of rigidity in robot multi-task synchronization mechanisms and chaotic resource management are solved, achieving efficient and secure multi-task collaborative synchronization and improving the system's flexibility and stability.

CN123068022APending Publication Date: 2026-11-10GREE ELECTRIC APPLIANCE INC OF ZHUHAI
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611240305.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-17
Publication Date
2026-11-10

AI Technical Summary

Technical Problem

Existing robot multi-task synchronization mechanisms are rigid, making it difficult to adapt to complex and dynamic multi-task collaborative scenarios. Furthermore, resource management is chaotic, which can easily lead to deadlocks and memory leaks.

Method used

By dynamically constructing a synchronization point structure containing an editable list of linked tasks, and utilizing a synchronization judgment mechanism based on the count of arrived tasks and the count of tasks to be woken up, dynamic synchronization point configuration across tasks is achieved, and a resource reclamation process is automatically executed after all tasks are woken up.

Benefits of technology

It improved development efficiency, achieved efficient and accurate multi-task synchronization, avoided deadlocks and memory leaks, and ensured the security and long-term stable operation of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123068022A_ABST
    Figure CN123068022A_ABST
Patent Text Reader

Abstract

This application provides a method, apparatus, device, and medium for multi-task collaborative synchronization of robots. The method includes: acquiring a multi-task robot project and preprocessing it to generate at least one synchronization point structure, the synchronization point structure including an editable list of linked tasks, an arrival task count, and a count of tasks to be woken up; when each task executes a preset multi-task synchronization instruction, matching the synchronization point structure corresponding to each task based on a preset matching rule, and updating the arrival task count; determining whether the updated arrival task count is equal to the count of tasks to be woken up; if not, the current task enters a blocked waiting state; if so, broadcasting to wake up all tasks in the blocked waiting state on the synchronization point structure, and automatically executing a synchronization point resource reclamation process. This application solves the problems of rigidity and chaotic thread resource management in existing multi-task robot synchronization mechanisms by constructing a synchronization point structure, a dual-count synchronization judgment mechanism, and a synchronization point resource reclamation process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of robot control technology, and in particular to a method, apparatus, device and medium for multi-task collaborative synchronization of robots. Background Technology

[0002] With the advancement of Industry 4.0, modern industrial robot systems generally adopt a multi-task parallel processing architecture, which schedules multiple sub-tasks to execute different action logics such as grasping, welding, and handling simultaneously through the main control unit, in order to improve production cycle and equipment utilization.

[0003] However, existing multi-task control systems suffer from significant drawbacks in traditional synchronization mechanisms when data interaction or action coordination between tasks is required: First, the definition of synchronization points is rigid. Traditional methods typically rely on hard-coded specific instructions or fixed variables for triggering, making it difficult to adapt to complex and dynamic multi-task collaborative scenarios. Once the production line cycle time is adjusted or the process flow changes, it is often necessary to modify the underlying code or even recompile, resulting in extremely high maintenance costs. Second, there is a lack of fault tolerance and timeout protection. When a task fails to reach the synchronization point due to mechanical failure, signal loss, or logical error, other waiting tasks will be blocked indefinitely, causing deadlock and halting the entire system. Furthermore, alarms cannot be triggered or safe states cannot be entered in a timely manner, seriously threatening production safety. Finally, resource management is chaotic. Existing synchronization structures are often not released in a timely manner after program execution, and there is a lack of effective mutex locks and condition variable mechanisms when multiple threads access them concurrently, which can easily lead to memory leaks, resource exhaustion, or data race problems. Summary of the Invention

[0004] This invention provides a method, apparatus, device, and medium for multi-task collaborative synchronization of robots, aiming to solve the technical problems of rigidity and chaotic thread resource management in existing multi-task synchronization mechanisms for robots.

[0005] In a first aspect, embodiments of the present invention provide a robot multi-task collaborative synchronization method, comprising: acquiring a robot multi-task project, and preprocessing the multi-task project to generate at least one synchronization point structure, the synchronization point structure including an editable list of linked tasks, an arrival task count, and a count of tasks to be woken up; when each task executes a preset multi-task synchronization instruction, matching the synchronization point structure corresponding to each task based on a preset matching rule, and updating the arrival task count; determining whether the updated arrival task count is equal to the count of tasks to be woken up; if not, the current task enters a blocked waiting state; if so, broadcasting to wake up all tasks in the blocked waiting state on the synchronization point structure, and automatically executing a synchronization point resource reclamation process.

[0006] Secondly, embodiments of the present invention also provide a robot multi-task collaborative synchronization device, which includes a unit for performing the above-described method.

[0007] Thirdly, embodiments of the present invention also provide a computer device, which includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the above-described method.

[0008] Fourthly, embodiments of the present invention also provide a computer-readable storage medium storing a computer program, the computer program including program instructions that, when executed by a processor, can implement the above-described method.

[0009] This application provides a method, apparatus, computer device, and storage medium for multi-task collaborative synchronization of robots. By dynamically constructing a synchronization point structure containing an editable linked task list, it solves the problem of poor flexibility caused by hard-coded synchronization logic, enabling dynamic configuration of synchronization points across tasks. Developers can dynamically define synchronization points and participating task lists at any location in the robot program without modifying the underlying thread scheduler, greatly improving development efficiency. Simultaneously, through a synchronization judgment mechanism based on the number of arrived tasks and the number of tasks to be awakened, efficient and accurate synchronization of multiple tasks is achieved. Through a synchronization point resource reclamation process, a resource reclamation function is automatically triggered after all tasks are awakened, ensuring thorough cleanup of synchronization objects after their lifecycle ends, avoiding memory leaks, and solving the technical problems of multi-threaded resource contention and leakage. This achieves the technical effects of efficient concurrency control and closed-loop resource management, ensuring the system's security and long-term stable operation. Attached Figure Description

[0010] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0011] Figure 1 This is a schematic flowchart of a robot multi-task collaborative synchronization method provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of a sub-process of the robot multi-task collaborative synchronization method provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of a sub-process of the robot multi-task collaborative synchronization method provided in an embodiment of the present invention; Figure 4 This is a schematic diagram of a sub-process of the robot multi-task collaborative synchronization method provided in an embodiment of the present invention; Figure 5 This is a schematic diagram of a sub-process of the robot multi-task collaborative synchronization method provided in an embodiment of the present invention; Figure 6 This is a schematic diagram of a sub-process of the robot multi-task collaborative synchronization method provided in an embodiment of the present invention; Figure 7 This is a schematic diagram of a sub-process of the robot multi-task collaborative synchronization method provided in an embodiment of the present invention; Figure 8 A schematic block diagram of a robot multi-task collaborative synchronization device provided in an embodiment of the present invention; Figure 9 A schematic block diagram of a computer device provided for an embodiment of the present invention. Detailed Implementation

[0012] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0013] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0014] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.

[0015] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0016] Please see Figure 1 This is a schematic flowchart of a robot multi-task collaborative synchronization method provided in an embodiment of the present invention. In this application, the robot multi-task collaborative synchronization method is applied in the field of robot control, and is particularly suitable for scenarios involving action timing coordination and data interaction synchronization under the parallel execution of multiple tasks in industrial robots, such as visual positioning and precise grasping coordination, multi-station welding linkage, and multi-robot material handling coordination.

[0017] For example, in industrial robot vision grasping applications, the system includes a vision positioning task and a precise grasping task. The grasping task can only execute the motion grasping action after the vision task calculates the precise coordinates of the target object; otherwise, grasping deviations will occur. This solution can achieve precise timing synchronization of the two tasks, while also possessing fault tolerance and automatic resource management capabilities.

[0018] This application provides a robot multi-task collaborative synchronization method, apparatus, device, and medium. The robot multi-task collaborative synchronization method includes: acquiring a robot multi-task project and preprocessing the multi-task project to generate at least one synchronization point structure, the synchronization point structure including an editable list of linked tasks, an arrival task count, and a pending task count; when each task executes a preset multi-task synchronization instruction, matching the synchronization point structure corresponding to each task based on a preset matching rule, and updating the arrival task count; determining whether the updated arrival task count is equal to the pending task count; if not, the current task enters a blocked waiting state; if so, broadcasting to wake up all tasks in the blocked waiting state on the synchronization point structure, and automatically executing a synchronization point resource reclamation process.

[0019] This application addresses the lack of flexibility caused by hard-coded synchronization logic by dynamically constructing a synchronization point structure containing an editable list of linked tasks. It enables dynamic configuration of synchronization points across tasks, allowing developers to dynamically define synchronization points and participating task lists at any point in the robot program without modifying the underlying thread scheduler, significantly improving development efficiency. Furthermore, a synchronization judgment mechanism based on the number of arrived tasks and the number of tasks waiting to be awakened achieves efficient and accurate synchronization across multiple tasks. Through a timeout circuit breaker mechanism and a synchronization point resource reclamation process, the system automatically triggers an alarm and terminates waiting when synchronization conditions are not met within a specified time, preventing system-wide paralysis due to individual task anomalies and resolving multi-task deadlock and system hangs caused by single-task failures, thus improving system robustness. Additionally, the automatic triggering of a resource reclamation function after all tasks are awakened ensures thorough cleanup of synchronization objects after their lifecycle ends, preventing memory leaks and resolving technical issues related to multi-threaded resource contention and leakage. This achieves efficient concurrency control and closed-loop resource management, guaranteeing system security and long-term stable operation.

[0020] Figure 1 This is a flowchart illustrating the robot multi-task collaborative synchronization method provided in an embodiment of the present invention. Figure 1 As shown, the method includes the following steps S10-S50.

[0021] S10. Obtain the robot multi-task engineering and preprocess the multi-task engineering to generate at least one synchronization point structure, the synchronization point structure containing an editable list of linked tasks, a count of arrived tasks, and a count of tasks to be woken up.

[0022] Specifically, the robot multitasking engineering refers to a robot program written by the user through a teach pendant or host computer, which contains multiple parallel sub-tasks. Each task can be created or deleted, including a main task that supports motion commands and sub-tasks that support non-motion commands. Each sub-task can respectively implement different functions such as motion control, visual detection, logic operation, IO interaction, and process processing.

[0023] The preprocessing refers to the operations performed by the interpreter to parse the synchronization point definition statements in the program, initialize resources, and create synchronization point structures after the robot multitasking project is started and before the multitasking project is actually run.

[0024] The synchronization point structure is an in-memory data structure that stores all synchronization-related parameters and resources. It is the core carrier for realizing multi-task synchronization and is used to manage all synchronization information of a synchronization point. The synchronization point structure includes a synchronization identifier, an editable linked task list, an arrival task count, and a pending task count. The synchronization identifier is a unique identifier corresponding to each synchronization point structure. The editable linked task list records the names of all tasks participating in the synchronization point, allowing users to flexibly add, delete, and modify tasks according to process requirements. Users can edit the tasks in the linked task list at any time through the teach pendant interface, and dynamically adjust the task objects participating in synchronization during runtime. The arrival task count counts the number of tasks that have reached the multi-task synchronization instruction position. The pending task count records the total number of tasks that need to reach the synchronization point in the current synchronization cycle, and its initial value is equal to the total number of tasks in the linked task list.

[0025] In the specific implementation process, the system first obtains the robot multi-task project written by the user, scans all the synchronization point configuration statements in the multi-task project, and identifies all the synchronization points that need to be created; then the interpreter performs preprocessing operations, creates a corresponding structure for each synchronization point in memory, configures an editable list of linked tasks for each structure, and initializes the initial values ​​of the arrival task count and the wake-up task count, thus completing the pre-configuration of the synchronization point structure.

[0026] Taking a visual grasping scenario as an example, the user defines a synchronization point SyncID_01, whose linked task list includes a visual positioning task and a precise grasping task, for a total of 2 tasks. In the preprocessing stage, the system creates a synchronization point structure corresponding to SyncID_01, sets the initial value of the arrival task count to 0, and the initial value of the waiting task count to 2, thus completing the initial configuration of the synchronization point.

[0027] This embodiment dynamically creates the synchronization point structure during the preprocessing stage and combines it with the editable linked task list to achieve flexible configuration of synchronization relationships. Users only need to modify the synchronization point definition or the linked task list in the program to adjust the combination of collaborative tasks without modifying the underlying scheduler code. This significantly reduces the maintenance cost of production line process iteration, improves the adaptability and scalability of the solution, and greatly improves development efficiency.

[0028] In one embodiment, such as Figure 2 As shown, step S10 includes steps S11-S12.

[0029] S11. Parse the synchronization point configuration information in the multi-task project, extract the synchronization identifier corresponding to each synchronization point and the linked task list, and determine the initial value of the count of tasks to be woken up based on the number of tasks in the linked task list. S12. Create the corresponding synchronization point structure in memory according to the synchronization identifier and the linked task list, initialize the arrival task count to zero, allocate a mutex lock and a condition variable to each synchronization point structure, and mark the synchronization point state of the synchronization point structure as active.

[0030] Specifically, the synchronization point configuration information refers to the synchronization relationship data predefined by the user in the teach pendant or programming environment, including the synchronization identifier (SyncID) of each synchronization point and the corresponding list of linked tasks.

[0031] The synchronization identifier is a unique identifier for each synchronization point, typically a string or numeric ID, used to achieve rapid mapping and matching between multi-task synchronization instructions and the synchronization point structure. The linked task list refers to the collection of names of all tasks participating in this synchronization point. This list is editable, allowing users to add or delete tasks at any time.

[0032] The mutex is a mutual exclusion component in the multi-threaded synchronization mechanism, used to ensure that only one thread can access the counter variable in the synchronization point structure at any given time, avoiding data races and numerical anomalies caused by concurrent modifications by multiple threads. The condition variable is the core carrier for implementing thread blocking and waking; the blocking, suspension, and broadcast wake-up of synchronization tasks are all based on the condition variable. The active state indicates that the synchronization point has completed resource initialization and can normally receive synchronization requests from tasks.

[0033] In the actual implementation process, the interpreter traverses all lines of code in the multi-task project, identifies all synchronization point definition instructions, extracts the synchronization identifier and the corresponding linked task list information line by line, counts the total number of associated tasks for each synchronization point, and uses the value of the total number of associated tasks as the initial value for the count of tasks to be awakened.

[0034] The system then allocates storage space of the corresponding size in the heap memory, creates an independent structure instance for each synchronization point, initializes the arriving task count to 0, sets the waiting task count to the total number of tasks counted above, initializes a mutex lock and a condition variable for each structure, and finally marks the structure's status field as "active", indicating that the synchronization point is ready to be called.

[0035] In this embodiment, the synchronization point structure is created during the interpreter preprocessing stage, corresponding to the initialization stage after the industrial robot program starts. Users do not need to manually request memory and initialize lock resources; all underlying operations are completed automatically by the system.

[0036] This embodiment uses synchronization identifiers to achieve unique identification and fast matching of synchronization points, ensuring accurate addressing of synchronization instructions in multi-task scenarios. At the same time, through the standardized configuration of mutex locks and condition variables, it provides a safe and reliable underlying support for subsequent multi-threaded synchronization, avoiding data race problems caused by concurrent access from a mechanism perspective. Furthermore, it achieves standardized management of the synchronization point lifecycle through unified state flags, providing a basis for judgment in subsequent resource reclamation.

[0037] S20. When each task executes the preset multi-task synchronization instruction, the synchronization point structure corresponding to each task is matched based on the preset matching rules, and the arrival task count is updated.

[0038] Specifically, the multi-task synchronization instruction is a synchronization trigger statement embedded in each task program. The instruction carries the identification information of the corresponding synchronization point. When the task executes the instruction, it triggers the synchronization waiting logic. The instruction prototype is WaitSyncTask(sync1, task1), where sync1 is the synchronization identifier and task1 is the task identifier.

[0039] The preset matching rule refers to the rule of one-to-one mapping matching based on the synchronization identifier. That is, when the synchronization identifier carried by the instruction is consistent with the synchronization identifier of the synchronization point structure, it is determined that the match is successful. The update of the arrival task count refers to incrementing the arrival task count value in the synchronization point structure by 1 to mark that the current task has arrived at the synchronization point. The arrival task count refers to the counter in the synchronization point structure that records the number of tasks that have arrived at the synchronization point.

[0040] In the specific implementation process, the multi-task scheduling module concurrently schedules each related task to execute independently. When any task runs to the preset multi-task synchronization instruction position, it first parses the synchronization identifier information carried by the instruction, and retrieves the corresponding synchronization point structure in the global synchronization point list based on the preset matching rules. After a successful match, the task thread acquires the mutex lock corresponding to the synchronization point, enters the critical section, and increments the value of the arriving task count by 1 in the critical section to complete the count update.

[0041] Taking the visual grasping scenario as an example, the precise grasping task is executed quickly. It first runs to the multi-task synchronization instruction WaitSyncTask(SyncID_01), extracts the synchronization identifier SyncID_01 and matches the corresponding synchronization point structure; the grasping task thread acquires the mutex lock and enters the critical section, updates the arrival task count from 0 to 1, and completes the count update operation.

[0042] This embodiment simplifies the user's programming logic and reduces the development difficulty of multi-task collaboration by using a unified multi-task synchronization instruction as the synchronization trigger entry point; it ensures the accurate correspondence between synchronization instructions and synchronization points through an identifier matching mechanism, avoiding synchronization anomalies caused by mismatches; and it ensures the accuracy of the count value in multi-threaded concurrent scenarios through the counter update operation protected by a mutex lock, avoiding logical errors caused by data races.

[0043] In one embodiment, such as Figure 3 As shown, the synchronization point structure also includes a synchronization identifier, and step S20 includes steps S21-S22.

[0044] S21. Extract the synchronization identifier carried by the multi-task synchronization instruction, and match the synchronization identifier of the multi-task synchronization instruction with the synchronization identifier of each synchronization point structure to confirm the synchronization point structure corresponding to the current task. S22. Obtain the mutex lock corresponding to the synchronization point structure to enter the critical section, and increment the value of the arrival task count by one within the critical section.

[0045] Specifically, the synchronization identifier refers to a globally unique synchronization point identifier (SyncID), which is passed as a parameter in the multi-task synchronization instruction to indicate the target synchronization point to be synchronized by the current task. The matching process adopts a key-value lookup method, using the synchronization identifier as the key to perform an exact match in the set of synchronization point structures.

[0046] The critical section refers to the code segment in a thread that accesses a shared resource (here, the count field of the synchronization point structure). Only one thread is allowed to enter the critical section at a time, and other threads must wait for the mutex lock to be released before they can enter. The incrementing by one refers to performing an atomic operation to increment the arrival count of the task by 1, marking a new task that has arrived at the synchronization point.

[0047] In the specific implementation process, when a task thread executes a multi-task synchronization instruction, it first extracts the synchronization identifier field from the instruction parameters; then, using the synchronization identifier as the search key, it searches in the globally maintained synchronization point hash table. If a structure with the exact same synchronization identifier is found, the match is considered successful, and the access pointer of the synchronization point structure is obtained.

[0048] After a successful match, the task thread calls the mutex lock locking function to acquire ownership of the mutex lock corresponding to the synchronization point and enters the critical section. Within the critical section, it performs an increment operation to check the count reached by 1. After the count update is completed, it maintains the mutex lock holding state and proceeds to the subsequent judgment logic.

[0049] After the operation is complete, the task thread calls the mutex release function to release the mutex and exit the critical section. The entire critical section operation takes a very short time, minimizing the lock holding time and reducing thread contention overhead. This embodiment achieves fast addressing of synchronization points through hash table matching, which has high matching efficiency and is suitable for complex multi-task scenarios with a large number of synchronization points. Through the critical section protection mechanism of "lock first, then modify", the atomicity of the counting modification operation is strictly guaranteed, completely avoiding the problem of numerical errors caused by multiple threads modifying the same variable at the same time, and ensuring the accuracy and reliability of the synchronization logic.

[0050] S30. Determine whether the updated arrival task count is equal to the waiting task count.

[0051] Specifically, this step is the core judgment step of the synchronization logic, used to determine whether all associated tasks have reached the synchronization point; the initial value of the count of tasks to be awakened is the total number of tasks in the linked task list, representing the total number of tasks that need to be reached; when the count of reached tasks equals this total value, it means that all tasks have reached the synchronization point and the synchronization triggering condition is met.

[0052] In the specific implementation process, after the task thread completes the update of the arrival count, it reads the current arrival count value and the initial baseline value of the count of tasks to be woken up in the critical section and performs an equality judgment. If the two are not equal, it means that there are still other tasks that have not reached the synchronization point, and enters the blocking waiting branch. If the two are equal, it means that all related tasks have arrived, and enters the broadcast wake-up branch.

[0053] Continuing with the example of the aforementioned visual grasping scenario, after the grasping task update count, the number of arriving tasks is 1, and the number of tasks to be woken up is 2. Since 1 is not equal to 2, it is determined that the synchronization condition is not met, and the process enters the blocking waiting branch.

[0054] This embodiment can determine the synchronization trigger condition by simply comparing numerical values. The logic is concise and clear, the execution efficiency is high, and it is easy to maintain and troubleshoot. Using count comparison as the only trigger condition ensures the accuracy of the synchronization trigger timing and ensures that all tasks are completed before subsequent actions are executed, thus avoiding timing errors.

[0055] S40. If not, the current task enters a blocked waiting state.

[0056] Specifically, the blocked waiting state refers to the thread pausing the execution of subsequent code and entering a sleep / suspended state. At this time, the thread does not occupy CPU computing resources and only waits for a wake-up signal or timeout signal to be triggered before resuming operation. This state is an operating system-level thread scheduling state, which can effectively reduce the system resource consumption when multiple tasks are waiting.

[0057] In the specific implementation process, when it is determined that the number of tasks that have arrived is not equal to the number of tasks that need to be woken up, it means that there are still other tasks that have not arrived at the synchronization point, and the current task needs to wait for the other tasks to arrive. At this time, the current task thread calls the thread wait function, enters the blocked waiting state on the condition variable, and actively releases the mutex lock it holds so that other tasks that arrive later can acquire the mutex lock and update the count. After the task enters the blocked state, it suspends the execution of subsequent instructions until it receives a wake-up signal or a timeout signal before exiting the blocked state and continuing to execute subsequent logic.

[0058] Following the previous example, after the grasping task determines that the synchronization condition is not met, the calling thread waits in the function and enters a blocked sleep state. At the same time, it releases the mutex lock, suspends the execution of subsequent grasping motion instructions, and waits for the visual task to reach the synchronization point and trigger the wake-up.

[0059] For example, when task B determines that the task count is not equal to the number of tasks waiting to be woken up, task B calls the thread wait function pthread_cond_timedwait(), passing in a condition variable and a preset timeout threshold T_timeout, and enters a blocked waiting state. Task B's program pauses execution, and the CPU resources it occupies are released for other tasks. Task B will wait on the condition variable until it is woken up by another task via pthread_cond_broadcast(), or until the timeout expires and it automatically wakes up. The B program waits at the WaitSyncTask instruction until it is woken up before continuing to move to point P1 to grab the object.

[0060] This embodiment uses an operating system-level blocking and waiting mechanism to allow the first arriving task to enter a low-power sleep state, eliminating the need to poll for synchronization status, significantly reducing CPU utilization and improving controller resource utilization. During the waiting process, the mutex lock is actively released to avoid blocking other tasks due to long-term lock occupation, ensuring that subsequent tasks can update the count normally and avoiding deadlock risks.

[0061] In one embodiment, such as Figure 4 As shown, step S40 includes steps S41-S43.

[0062] S41. When the number of arrived tasks is not equal to the number of tasks to be woken up, control the current task to call the thread wait function to enter the blocked wait state. S42. Calculate the waiting time for the current task to enter the blocked waiting state; S43. If the waiting time is greater than the preset timeout threshold, and no broadcast wake-up signal is received within the waiting time, then a timeout is determined and an exception handling process is triggered.

[0063] Specifically, the thread wait function is a timed wait function that supports a timeout mechanism. It can use the POSIX standard pthread_cond_timedwait() function, which supports setting the maximum wait time and automatically returns an error code after the timeout. This function puts the calling thread into the wait queue of the condition variable and releases the corresponding mutex lock, causing the thread to enter a blocked sleep state. After the function returns, the thread will reacquire the mutex lock.

[0064] The waiting time refers to the accumulated time since the current task entered the blocked waiting state. This time is used to compare with the preset timeout threshold to determine whether a timeout has occurred.

[0065] The timeout threshold is the maximum waiting time preset by the user based on the process cycle time and fault tolerance requirements. The typical value range is 5 to 10 seconds, which can be flexibly adjusted according to specific scenarios.

[0066] The exception handling process refers to the fault handling logic executed by the system after a timeout is triggered, which includes fault recording, alarm triggering, resource release and safety reset.

[0067] In the specific implementation process, when it is determined that the synchronization condition is not met (that is, the updated number of arriving tasks is not equal to the number of tasks to be woken up), the task thread calls the thread wait function with timeout parameter, passes in the preset timeout threshold, and enters the blocked wait state on the condition variable; the system kernel starts timing and counts the blocked wait time of the task.

[0068] If the task receives a broadcast wake-up signal within the timeout threshold, it will exit the blocked waiting state normally and continue to execute subsequent instructions; if the waiting time reaches the preset timeout threshold and no broadcast wake-up signal is received, the thread waiting function will return a timeout error code, which is determined to be a synchronization timeout and triggers the exception handling process.

[0069] Specifically, the exception handling process includes: recording the timeout fault number, occurrence time, involved synchronization point ID, and task information in the controller's local log; driving the control cabinet's audible and visual alarm to emit a fault prompt sound and flashing warning lights; sending fault codes and alarm information to the production line's host computer; forcibly releasing the mutex lock and structure memory resources corresponding to the synchronization point, causing all blocked tasks to exit the waiting state, enter the robot safety reset process, stop all motion output, and maintain the current posture while waiting for maintenance personnel to investigate.

[0070] For example, after determining that the number of tasks that have arrived is not equal to the number of tasks waiting to be woken up, task B calls `pthread_cond_timedwait(&cond,&mutex,&abstime)`. Upon this call, the system automatically adds task B's thread to the wait list of the `SyncID_01` condition variable and releases the previously held mutex, causing task B to enter a blocked waiting state. When executing `pthread_cond_timedwait()`, the system passes in an absolute time point `abstime` calculated based on the current system clock plus a timeout threshold. For example, if the current system time is `t0` and the timeout threshold is 5 seconds, then `abstime = t0 + 5 seconds`. The function continuously monitors the comparison between the current system time and `abstime`. When the system time reaches or exceeds `abstime`, it automatically determines a timeout and returns. If task A fails to reach the synchronization point within 5 seconds due to a visual positioning failure, and task B waits for more than 5 seconds in `pthread_cond_timedwait()` without receiving a broadcast wake-up signal, the function returns a timeout error code (such as `ETIMEDOUT`). Upon detecting the error code, the exception handling module intervenes immediately: First, it records the timeout alarm number and timestamp in the robot controller's internal log for easy troubleshooting. Second, it triggers an audible and visual alarm to alert on-site operators. Then, it sends the fault code to the host computer, informing the remote monitoring system of the abnormal state. Finally, it forcibly releases the mutex lock and memory resources corresponding to SyncID_01, causing task B to exit the blocked waiting state and enter the safe reset process.

[0071] The safety reset process refers to the process where, when an alarm is triggered and the robot enters a fault state, all tasks must be released, the alarm cleared, and the robot restarted. This involves re-executing operations such as creation and initialization, including initializing the robot's state machine and releasing engineering resources. Since all states need to be reset after an industrial robot alarm, memory resources need to be cleared to prevent memory leaks.

[0072] For example, in a visual grasping scenario, if an industrial camera experiences a communication failure, causing the visual positioning task to be unable to complete calculations or reach the synchronization point for an extended period, the grasping task will trigger a timeout exception after waiting for more than the preset 8-second timeout threshold. The system will immediately record the fault log, trigger an audible and visual alarm, and forcibly release the synchronization point resource. The robot will stop all actions and enter a safe state, preventing the equipment from waiting idly for a long time or malfunctioning.

[0073] This embodiment fundamentally avoids system-wide deadlock caused by single-task anomalies through a built-in timeout circuit breaker mechanism. Even if individual tasks fail, it will not cause other tasks to be permanently blocked, greatly improving the robustness and fault self-healing capability of the multi-task collaborative system. The standardized anomaly handling process enables rapid fault reporting and safe shutdown, ensuring the safety of industrial production, while also facilitating maintenance personnel to quickly locate problems and shorten downtime.

[0074] S50. If so, broadcast to wake up all tasks in the blocked waiting state on the synchronization point structure and automatically execute the synchronization point resource reclamation process.

[0075] Specifically, the broadcast wake-up refers to sending a wake-up signal to all blocked threads waiting on the same condition variable, causing all threads to simultaneously exit the blocked state and resume operation. The synchronization point resource reclamation process refers to the operation of automatically releasing all system resources occupied by the synchronization point structure after synchronization is completed, including memory, mutexes, condition variables, etc., to achieve closed-loop resource management.

[0076] In the specific implementation process, when the last task arrives at the synchronization point, after updating the count and determining that the number of arriving tasks equals the number of tasks waiting to be woken up, it means that all related tasks have arrived and the synchronization trigger condition is met. At this time, the current task acts as the trigger and calls the broadcast wake-up function to send a wake-up signal to all blocked tasks waiting on this condition variable. All awakened tasks synchronously exit the blocked state and continue to execute their subsequent instruction code. After all tasks have been woken up and exited, the system automatically executes the synchronization point resource reclamation process to release all system resources occupied by the synchronization point.

[0077] For example, when task A reaches the synchronization point and updates the arrival count to 2, it determines that the arrival count 2 equals the wake-up count 2, thus satisfying the synchronization trigger condition. Task A calls pthread_cond_broadcast(&cond), and the system iterates through the wait list of the SyncID_01 condition variable, switching task B from the blocked waiting state to the ready running state. Task A simultaneously clears the wake-up count to zero to indicate the end of this synchronization cycle. Task B continues execution, moving to the visually altered point to complete precise capture.

[0078] After the synchronization instruction is executed, the system automatically triggers the resource reclamation function to clear the temporary data in the synchronization point structure (including the arrival count of tasks in the current synchronization cycle, timeout flag, etc.), and release the memory resources occupied by the structure in the preprocessing stage to avoid memory overflow.

[0079] Taking the visual grasping scenario as an example, after the visual positioning task completes the photo taking and coordinate calculation, it runs to the multi-task synchronization instruction; after acquiring the mutex lock, it updates the arrival count from 1 to 2, at which point the arrival count is equal to the waiting-to-wake count of 2; the visual task calls the broadcast wake-up function to send a wake-up signal to the grasping task; after receiving the signal, the grasping task exits the blocked state and executes subsequent instructions synchronously with the visual task, and the grasping task moves to the target point calculated by the vision to perform the grasping action.

[0080] This embodiment achieves the synchronous startup of all tasks through a broadcast wake-up mechanism, ensuring the precise alignment of the timing of multi-task actions and meeting the timing requirements of collaborative operations. Through an automatic resource reclamation process, the system can automatically clean up resources at synchronization points without requiring users to manually write resource release code, avoiding memory leaks and resource residues and improving the stability of the controller's long-term continuous operation.

[0081] In one embodiment, such as Figure 5 As shown, step S50 includes steps S51-S52.

[0082] S51. When the number of arriving tasks equals the number of tasks to be woken up, control the current task to call the thread to broadcast the wake-up function and traverse the list of waiters associated with the synchronization point structure. S52. Switch each thread in the waiter list from the blocked waiting state to the ready running state, and clear the count of the tasks to be woken up to indicate the end of the current synchronization cycle.

[0083] Specifically, the thread broadcast wake-up function can be the POSIX standard pthread_cond_broadcast() function, which is used to wake up all threads waiting on a specified condition variable. The pthread_cond_broadcast() function performs the following: the system looks at the "wait list" associated with the condition variable, iterates through the list, and changes the state of each thread in the list from "sleep / blocked" to "ready / runnable".

[0084] The waiter list is a queue of all blocked threads waiting on this condition variable, maintained by the operating system kernel; the ready-to-run state refers to the state in which a thread is qualified to run and can be scheduled for execution by the operating system; the current synchronization cycle refers to the complete synchronization process from the arrival of the first task at the synchronization point to the wake-up and exit of all tasks.

[0085] In practice, once the count of the last arriving task is equal to the count of the waiting task, the thread broadcast wake-up function is called. The operating system kernel iterates through the list of waiters associated with the condition variable, wakes up all threads in the blocked waiting state, and switches their state from blocked to ready, waiting for CPU scheduling and execution. At the same time, the current task clears the count of tasks to be woken up in the synchronization point structure to zero, marking the completion of the wake-up operation in this synchronization cycle. Each subsequent wake-up thread will update the count of tasks to be woken up again when it exits the blocked state, which will be used for triggering judgments for subsequent resource reclamation.

[0086] For example, when task A updates the arrival count to 2, it determines that the arrival count of 2 equals the count of tasks waiting to be woken up, which is 2. Task A calls `pthread_cond_broadcast(&cond)`, and the system kernel checks the list of waiters associated with the `SyncID_01` condition variable. In this list, the thread of task B, having been placed there due to a previous call to `pthread_cond_timedwait()`, is in a blocked waiting state. The system iterates through this list and switches the thread state of task B from the blocked waiting state to the runnable state. Task B then participates in the CPU's scheduling competition, obtains a time slice, returns from the `pthread_cond_timedwait()` function, and continues executing subsequent instructions (i.e., moving to point P1 to perform precise fetching). At the same time, task A clears the count of tasks waiting to be woken up in the synchronization point structure from 2 to 0, indicating that this round of synchronization has been successfully completed. The synchronization in this embodiment is just one step in the complex process of robotics. Industrial robots typically operate in a cyclical or assembly-line manner, and a single synchronization may only correspond to a momentary action in the process. After synchronization is completed, each task continues to execute the next instruction of its respective process. If a new task subsequently needs to perform the synchronization operation at the same synchronization point, the count of tasks awaiting awakening will be reinitialized.

[0087] This embodiment wakes up all blocked waiting tasks at once through a broadcast wake-up mechanism, ensuring a high degree of consistency in the startup sequence of all tasks and high synchronization accuracy. By switching all threads in the waiter list to the ready state, it achieves precise synchronous release of multiple tasks at the same synchronization point. By marking the synchronization cycle status by clearing the wake-up count, it achieves traceability of the synchronization process and provides a basis for judgment in subsequent resource reclamation.

[0088] In one embodiment, such as Figure 6 As shown, step S50 also includes steps S53-S54.

[0089] S53. After the broadcast wake-up operation is completed and all woken-up tasks continue to execute their respective subsequent instructions, the resource reclamation function is automatically called. S54. The temporary data in the synchronization point structure is cleared by the resource reclamation function, and the memory resources occupied by the synchronization point structure in the preprocessing stage are released.

[0090] Specifically, the resource reclamation function is a built-in resource cleanup function used to perform the destruction operation of the synchronization point structure. It is automatically triggered and called after the synchronization operation is completed. The temporary data refers to dynamic data generated in the current synchronization cycle that is no longer needed before the next synchronization. It includes at least the arrival count of tasks in the current synchronization cycle, the timeout flag, and the list of tasks participating in the arrival of tasks in this cycle. For example, if task A executes the synchronization point instruction but task B has not yet executed the synchronization point instruction, and other alarms are triggered, the structure memory resources in this case are called temporary resources. Because all states of the industrial robot need to be restarted after an alarm, the memory resources need to be cleared. The memory resources include the heap memory occupied by the synchronization point structure itself, and the system kernel resources occupied by mutexes and condition variables.

[0091] In practice, each awakened task, after exiting the blocked waiting state, will reacquire the mutex lock, enter the critical section, decrement the count of tasks to be awakened by 1, release the mutex lock, and continue to execute its subsequent program instructions.

[0092] When the last awakened task performs a decrement operation, the count of tasks to be awakened becomes 0. At this point, it is determined that all associated tasks have completed synchronization and exited the waiting state, and the system automatically triggers the resource reclamation function.

[0093] The resource reclamation function should perform at least the following operations: destroy the mutex and condition variable corresponding to the synchronization point, and release kernel resources; clear all temporary count fields and status fields in the structure; release the heap memory space occupied by the synchronization point structure; remove the synchronization point from the global synchronization point list, and complete the closed-loop management of resources for this synchronization.

[0094] For example, after task A calls `pthread_cond_broadcast()` to wake up task B, both tasks continue execution: task B moves to point P1 to perform a precise fetch, while task A executes its subsequent instructions. After both tasks have left the synchronization point and continued executing their respective subsequent instructions, the system automatically calls the resource reclamation callback function in the synchronization point management module. This callback function is registered when the synchronization point structure is created and is automatically triggered after the synchronization cycle is completed, without requiring manual calling from the application layer. After the resource reclamation function is called, it first resets the arrival task count in the synchronization point structure to 0, clears the timeout flag, and clears the list of arrival tasks for this round. Subsequently, the function calls `pthread_mutex_destroy()` to destroy the mutex lock and `pthread_cond_destroy()` to destroy the condition variable, releasing the synchronization primitive resources at the operating system level. Finally, the function calls `free()` or `delete` to release the heap memory space occupied by the synchronization point structure, returning the memory to the system memory pool. After the synchronization point structure is released, the memory it occupies can be reused by the creation of other data structures. Industrial robots may undergo tens of thousands or even hundreds of thousands of synchronous operations during long-term operation. If memory is not released during each synchronization, the accumulated memory will gradually be exhausted, eventually leading to system crash.

[0095] This embodiment accurately identifies and completes synchronization nodes by counting the decreasing count of nodes to be woken up, and automatically triggers resource reclamation. It realizes complete resource lifecycle management from "application-use-release" and can automatically complete resource cleanup without manual intervention, effectively avoiding memory leaks and resource exhaustion problems, and significantly improving the stability of long-term continuous operation of industrial robot controllers. At the same time, the resource reclamation logic is transparent to upper-level users, who do not need to pay attention to the details of underlying resource management, reducing programming difficulty and maintenance costs.

[0096] Furthermore, the callback function mechanism separates resource reclamation logic from business logic, improving code modularity and maintainability; by clearing temporary data and releasing memory resources, closed-loop management of synchronization point resources is achieved, ensuring stable and controllable memory usage during long-term system operation; and by destroying mutex locks and condition variables, the problem of system resource exhaustion caused by residual synchronization primitives is avoided.

[0097] In one embodiment, such as Figure 7 As shown, the linked task list includes a normal task group and a critical task group, the count of tasks to be awakened is the total number of tasks in the critical task group, and the method further includes steps S110-S150.

[0098] S110. When each task executes the preset multi-task synchronization instruction, the synchronization point structure corresponding to each task is matched based on the preset matching rules. S120. Determine whether the current task belongs to the critical task group. If so, update the arrival task count. S130. Determine whether the updated arrival task count is equal to the pending wake-up task count; S140. If not, the current task enters a blocked waiting state; S150. If so, broadcast to wake up all tasks in the blocked waiting state on the synchronization point structure and automatically execute the synchronization point resource reclamation process.

[0099] Specifically, the "ordinary task group" and "critical task group" are classifications of tasks in the linked task list made by the user when configuring synchronization points. The critical task group refers to the set of tasks that affect the core process timing and must participate in synchronization. Tasks in the critical task group have a decisive impact on synchronization triggering; the synchronization wake-up operation is triggered only when all tasks in the critical task group reach the synchronization point. The ordinary task group refers to the set of auxiliary tasks that have a smaller impact on synchronization timing and are allowed to be late or absent. Tasks in the ordinary task group do not have a decisive impact on synchronization triggering; even if they do not arrive, they will not prevent synchronization triggering. In this embodiment, the count of tasks to be woken up is only equal to the total number of tasks in the critical task group, not the total number of tasks in the entire linked task list.

[0100] In the specific implementation process, when users define synchronization points, the list of linked tasks can be divided into critical task groups and ordinary task groups. The count of tasks to be woken up is set to the total number of tasks in the critical task group. Only the arrival of critical tasks will update the count of arriving tasks, while the arrival of ordinary tasks will not affect the count statistics.

[0101] When a task executes a multi-task synchronization instruction, it first matches the corresponding synchronization point structure, and then determines the group to which the current task belongs. If it belongs to the critical task group, it executes the arrival count update and enters the subsequent count judgment and blocking / wake-up logic. If it belongs to the ordinary task group, it does not update the count and directly continues to execute subsequent instructions without participating in synchronization waiting.

[0102] When all critical tasks reach the synchronization point, i.e., when the count of arrived tasks equals the count of tasks waiting to be woken up, a broadcast wake-up is immediately triggered, and all waiting tasks execute subsequent actions synchronously; even if ordinary tasks have not yet arrived, it does not affect the timing of the synchronization trigger.

[0103] For example, in a multi-station welding scenario, the main welding task and the positioner control task are set as the critical task group, and the dust removal auxiliary task is set as the ordinary task group. As long as the main welding task and the positioner task reach the synchronization point, the synchronous welding action is immediately triggered without waiting for the dust removal task to be fully in place. This improves the production cycle efficiency while ensuring the safety of the core process.

[0104] This embodiment employs an asymmetric synchronization mode to group and manage the linked task list. While retaining all task information, it assigns different synchronization weights to different tasks, allowing users to configure tasks hierarchically based on process importance. This flexibly adapts to the timeliness requirements of different scenarios, preventing delays in minor tasks from slowing down the overall production line cycle time and improving the flexibility and scenario adaptability of the synchronization mechanism. Simultaneously, it retains the basic logic of equal synchronization, is compatible with traditional synchronization requirements, and allows for flexible switching of modes according to actual scenarios. Furthermore, by determining whether the current task belongs to a critical task group, a differentiated synchronization strategy is implemented. Critical tasks control synchronization triggering, while ordinary tasks are not subject to synchronization blocking restrictions, effectively adapting to the timeliness requirements of different processes. By only blocking and waiting for critical tasks, the number of blocked tasks in the system is reduced, task scheduling overhead is lowered, and the overall parallel efficiency of the system is improved. By introducing an asymmetric synchronization strategy, while retaining equal synchronization capabilities, it adds flexible options for majority synchronization and priority synchronization, enabling users to flexibly configure synchronization strategies according to the timeliness requirements of different process scenarios, further expanding the applicability of this invention.

[0105] In addition, the linked task list also supports dynamic adjustment at runtime. Through the dynamic configuration interface, subtasks can be added to the synchronization point structure or completed tasks can be removed. The corresponding values ​​of the count of tasks to be woken up and the count of tasks that have arrived are updated synchronously to adapt to complex production scenarios where tasks are dynamically generated, thereby further improving the scalability of the solution.

[0106] This application generates a synchronization point structure containing an editable list of linked tasks during the preprocessing stage, enabling dynamic binding and flexible configuration of synchronization relationships. It achieves efficient and accurate synchronization of multiple tasks through a synchronization judgment mechanism based on the number of arrived tasks and the number of tasks to be woken up. It prevents system deadlocks caused by single-task anomalies by introducing a timeout circuit breaker mechanism. Furthermore, it achieves closed-loop management of memory resources through a synchronization point resource reclamation process. Therefore, this solution can achieve dynamic synchronization point configuration without modifying the underlying thread scheduler, possessing high flexibility and maintainability. Simultaneously, through timeout protection and automatic resource reclamation, it significantly improves the system's security, stability, and long-term operational reliability, greatly reducing code maintenance costs and system failure risks during production line changes.

[0107] Figure 8 This is a schematic block diagram of a robot multi-task collaborative synchronization device 300 provided in an embodiment of the present invention. Figure 8 As shown, corresponding to the above-described robot multi-task cooperative synchronization method, the present invention also provides a robot multi-task cooperative synchronization device 300. This robot multi-task cooperative synchronization device 300 includes a unit for executing the above-described robot multi-task cooperative synchronization method, and the device can be configured in a computer device. Specifically, please refer to... Figure 8The robot multi-task collaborative synchronization device 300 includes a preprocessing unit 301, a synchronization matching unit 302, a judgment unit 303, a blocking and waiting unit 304, and a wake-up and recycling unit 305.

[0108] The preprocessing unit 301 is used to acquire the robot's multi-task engineering and preprocess the multi-task engineering to generate at least one synchronization point structure, the synchronization point structure including an editable list of linked tasks, a count of arrived tasks and a count of tasks to be woken up. The synchronization matching unit 302 is used to match the synchronization point structure corresponding to each task based on the preset matching rules and update the arrival task count when each task executes the preset multi-task synchronization instruction. The judgment unit 303 is used to determine whether the updated arrival task count is equal to the wake-up task count; The blocking and waiting unit 304 is used to control the current task to enter the blocking and waiting state if the number of tasks reached is not equal to the number of tasks to be woken up. The wake-up and recycling unit 305 is used to broadcast and wake up all tasks in the blocked waiting state on the synchronization point structure if the number of tasks reached equals the number of tasks to be woken up, and automatically execute the synchronization point resource recycling process.

[0109] In one embodiment, the preprocessing unit 301 includes a parsing subunit and a creation subunit.

[0110] The parsing subunit is used to parse the synchronization point configuration information in the multi-task project, extract the synchronization identifier corresponding to each synchronization point and the linked task list, and determine the initial value of the count of tasks to be woken up based on the number of tasks in the linked task list. A subunit is created to create the corresponding synchronization point structure in memory based on the synchronization identifier and the linked task list, initialize the arrival task count to zero, allocate a mutex lock and a condition variable to each synchronization point structure, and mark the synchronization point state of the synchronization point structure as active.

[0111] In one embodiment, the synchronization point structure further includes a synchronization identifier, and the matching update unit 302 includes a matching subunit and an accumulation subunit.

[0112] The matching subunit is used to extract the synchronization identifier carried by the multi-task synchronization instruction, and match the synchronization identifier of the multi-task synchronization instruction with the synchronization identifier of each synchronization point structure to confirm the synchronization point structure corresponding to the current task. An accumulation subunit is used to acquire the mutex lock corresponding to the synchronization point structure to enter the critical section, and to increment the value of the arrival task count by one within the critical section.

[0113] In one embodiment, the blocking unit 304 includes a waiting subunit, a timing subunit, and a timeout subunit.

[0114] The waiting subunit is used to control the current task to call the thread waiting function to enter a blocked waiting state when the number of arrived tasks is not equal to the number of tasks to be woken up. The timing subunit is used to calculate the waiting time for the current task to enter the blocked waiting state; The timeout subunit is used to determine a timeout and trigger an exception handling process if the waiting time is greater than a preset timeout threshold and no broadcast wake-up signal is received within the waiting time.

[0115] In one embodiment, the wake-up and recycling unit 305 includes a broadcast subunit and a state switching subunit.

[0116] The broadcast subunit is used to control the current task to call the thread broadcast wake-up function and traverse the list of waiters associated with the synchronization point structure when the number of arriving tasks equals the number of tasks to be woken up. The state switching subunit is used to switch each thread in the waiter list from the blocked waiting state to the ready running state, and to clear the count of the tasks to be woken up to indicate the end of the current synchronization cycle.

[0117] In one embodiment, the wake-up recycling unit 305 further includes a recycling call subunit and a memory release subunit.

[0118] The resource reclamation call subunit is used to automatically call the resource reclamation function after the broadcast wake-up operation has been completed and all woken-up tasks have continued to execute their subsequent instructions; The memory release subunit is used to clear the temporary data in the synchronization point structure through the resource reclamation function and release the memory resources occupied by the synchronization point structure in the preprocessing stage.

[0119] In one embodiment, the linked task list includes a normal task group and a critical task group, the count of tasks to be woken up is the total number of tasks in the critical task group, and the device further includes a group synchronization unit, the group synchronization unit comprising: The structure matching subunit is used to match the synchronization point structure corresponding to each task based on the preset matching rules when each task executes the preset multi-task synchronization instruction. The grouping judgment subunit is used to determine whether the current task belongs to the critical task group. If so, the arrival task count is updated. The group comparison subunit is used to determine whether the updated arrival task count is equal to the wake-up task count; The group blocking subunit is used to make the current task enter a blocking waiting state if no; The group wake-up subunit is used to broadcast wake-up to all tasks in a blocked waiting state on the synchronization point structure if the condition is met, and automatically execute the synchronization point resource reclamation process.

[0120] It should be noted that those skilled in the art can clearly understand that the specific implementation process of the above-mentioned robot multi-task collaborative synchronization device and each unit can be referred to the corresponding description in the foregoing method embodiments. For the sake of convenience and brevity, it will not be repeated here.

[0121] The aforementioned robot multi-task collaborative synchronization device 300 can be implemented as a computer program, which can, for example... Figure 9 It runs on the computer device shown.

[0122] Please see Figure 9 , Figure 9 This is a schematic block diagram of a computer device provided in an embodiment of this application. The computer device 500 can be a terminal or a server. The terminal can be an electronic device with communication functions, such as a smartphone, tablet, laptop, desktop computer, personal digital assistant, or wearable device. The server can be a standalone server or a server cluster composed of multiple servers.

[0123] See Figure 9 The computer device 500 includes a processor 502, a memory, and a network interface 505 connected via a system bus 501. The memory may include a non-volatile storage medium 503 and internal memory 504.

[0124] The non-volatile storage medium 503 may store an operating system 5031 and a computer program 5032. The computer program 5032 includes program instructions that, when executed, cause the processor 502 to perform a robot multi-task cooperative synchronization method.

[0125] The processor 502 provides computing and control capabilities to support the operation of the entire computer device 500.

[0126] The internal memory 504 provides an environment for the operation of the computer program 5032 in the non-volatile storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute a robot multi-task cooperative synchronization method.

[0127] This network interface 505 is used for network communication with other devices. Those skilled in the art will understand that... Figure 9The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device 500 to which the present application is applied. The specific computer device 500 may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0128] The processor 502 is used to run the computer program 5032 stored in the memory to implement the steps of the above-described robot multi-task collaborative synchronization method.

[0129] It should be understood that in the embodiments of this application, the processor 502 may be a central processing unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.

[0130] It will be understood by those skilled in the art that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program includes program instructions and can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiments of the above methods.

[0131] Therefore, the present invention also provides a storage medium. This storage medium can be a computer-readable storage medium. The storage medium stores a computer program, wherein the computer program includes program instructions. When executed by a processor, the program instructions cause the processor to perform the steps of the above-described robot multi-task cooperative synchronization method.

[0132] The storage medium can be any computer-readable storage medium capable of storing program code, such as a USB flash drive, portable hard drive, read-only memory (ROM), magnetic disk, or optical disk.

[0133] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0134] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For example, the division of each unit is merely a logical functional division, and there may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.

[0135] The steps in the method of this invention can be adjusted, merged, or reduced in order according to actual needs. The units in the device of this invention can be merged, divided, or reduced according to actual needs. Furthermore, the functional units in the various embodiments of this invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0136] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.

[0137] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A method for multi-task collaborative synchronization of robots, characterized in that, The method includes: Obtain the robot's multi-task engineering and preprocess the multi-task engineering to generate at least one synchronization point structure, the synchronization point structure containing an editable list of linked tasks, a count of arrived tasks, and a count of tasks to be woken up; When each task executes the preset multi-task synchronization instruction, the synchronization point structure corresponding to each task is matched based on the preset matching rules, and the arrival task count is updated. Determine whether the updated arrival count is equal to the count of tasks to be woken up; If not, the current task enters a blocked waiting state; If so, the system will broadcast to wake up all tasks that are in a blocked waiting state on the synchronization point structure and automatically execute the synchronization point resource reclamation process.

2. The method according to claim 1, characterized in that, The steps of acquiring the robot's multi-task engineering and preprocessing the multi-task engineering to generate at least one synchronization point structure, wherein the synchronization point structure includes an editable list of linked tasks, an arrival count of tasks, and a count of tasks to be woken up, include: The synchronization point configuration information in the multi-task project is parsed, the synchronization identifier corresponding to each synchronization point and the linked task list are extracted, and the initial value of the count of tasks to be woken up is determined according to the number of tasks in the linked task list. Based on the synchronization identifier and the linked task list, a corresponding synchronization point structure is created in memory, the arrival task count is initialized to zero, a mutex lock and a condition variable are allocated to each synchronization point structure, and the synchronization point state of the synchronization point structure is marked as active.

3. The method according to claim 1, characterized in that, The synchronization point structure also includes a synchronization identifier. The step of matching the synchronization point structure corresponding to each task based on a preset matching rule and updating the arrival task count when each task executes a preset multi-task synchronization instruction includes: Extract the synchronization identifier carried by the multi-task synchronization instruction, and match the synchronization identifier of the multi-task synchronization instruction with the synchronization identifier of each synchronization point structure to confirm the synchronization point structure corresponding to the current task. Acquire the mutex lock corresponding to the synchronization point structure to enter the critical section, and increment the value of the arrival task count by one within the critical section.

4. The method according to claim 1, characterized in that, If not, the step of the current task entering a blocked waiting state includes: When the number of arrived tasks is not equal to the number of tasks to be woken up, control the current task to call the thread wait function to enter a blocked waiting state; Calculate the waiting time for the current task to enter the blocked waiting state; If the waiting time is greater than the preset timeout threshold, and no broadcast wake-up signal is received within the waiting time, a timeout is determined and an exception handling process is triggered.

5. The method according to claim 1, characterized in that, If so, then broadcast wake-up calls to all tasks in a blocked waiting state on the synchronization point structure, and automatically execute the synchronization point resource reclamation process, including: When the number of arriving tasks equals the number of tasks to be woken up, control the current task to call the thread to broadcast the wake-up function and traverse the list of waiters associated with the synchronization point structure; Each thread in the waiter list is switched from the blocked waiting state to the ready running state, and the count of tasks to be woken up is cleared to indicate the end of the current synchronization cycle.

6. The method according to claim 1, characterized in that, If so, the step of broadcasting to wake up all tasks in a blocked waiting state on the synchronization point structure and automatically executing the synchronization point resource reclamation process also includes: After the broadcast wake-up operation is completed and all woken-up tasks continue to execute their subsequent instructions, the resource reclamation function is automatically invoked. The resource reclamation function clears the temporary data in the synchronization point structure and releases the memory resources occupied by the synchronization point structure during the preprocessing stage.

7. The method according to claim 1, characterized in that, The linked task list includes a regular task group and a critical task group, the count of tasks to be awakened is the total number of tasks in the critical task group, and the method further includes: When each task executes the preset multi-task synchronization instruction, the synchronization point structure corresponding to each task is matched based on the preset matching rules; Determine whether the current task belongs to the critical task group; if so, update the arrival task count. Determine whether the updated arrival count is equal to the count of tasks to be woken up; If not, the current task enters a blocked waiting state; If so, the system will broadcast to wake up all tasks that are in a blocked waiting state on the synchronization point structure and automatically execute the synchronization point resource reclamation process.

8. A robot multi-task collaborative synchronization device, characterized in that, Includes a unit for performing the method as described in any one of claims 1-7.

9. A computer device, characterized in that, The computer device includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the method as described in any one of claims 1-7.

10. A storage medium, characterized in that, The storage medium stores a computer program, which includes program instructions that, when executed by a processor, can implement the method as described in any one of claims 1-7.