A multi-thread control method, device, equipment and storage medium

By detecting the child thread creation code in the main thread and automatically creating parallel parsing child threads, the problem of low efficiency of multi-thread control in the existing technology is solved, and efficient parallel parsing and simplified multi-thread control process is realized.

CN115080155BActive Publication Date: 2025-07-29SHANGHAI JIEKA ROBOT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210657503.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-10
Publication Date
2025-07-29
Estimated Expiration
2042-06-10

AI Technical Summary

Technical Problem

In the prior art, when a robot executes a job program, multi-threaded control methods rely on specific technical thresholds and may involve parser reconstruction, making it difficult to achieve efficient parallel parsing.

Method used

The main thread detects the child thread creation code, automatically creates the child thread and parses the associated second source code file, and realizes parallel parsing between the main thread and the child thread.

Benefits of technology

It improves the efficiency and accuracy of multi-threaded control, simplifies the implementation process of multi-threaded control, and reduces the complexity and dependencies of script parsing modules.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115080155B_ABST
    Figure CN115080155B_ABST
Patent Text Reader

Abstract

The present invention discloses a multi-thread control method, apparatus, device and storage medium. The method includes: during the process of parsing a first source code file by a main thread, the main thread detects a sub-thread creation code and creates a sub-thread; parsing a second source code file associated with the sub-thread creation code by the sub-thread; and executing the parsed parsing instructions. The embodiments of the present invention can realize automatic creation and parsing of multi-threads, so as to realize parallel execution of the parsing instructions obtained by multi-threads, and simplify the implementation process of the multi-thread control method.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer control technology, and in particular, to a multi-thread control method, apparatus, device, and storage medium. Background Art

[0002] During the process of a robot executing a job program, for the characteristic of parallel execution of tasks, script multi-threading can be extended and implemented based on the LUA (programming language) solution, or multi-threading can be implemented by writing a custom parser. However, these methods rely on specific technologies, have certain technical thresholds, and may involve the reconstruction of the entire parser. Summary of the Invention

[0003] The present invention provides a multi-thread control method, apparatus, device, and storage medium to implement parallel parsing of parsing instructions by multi-threading and simplify the implementation process of the multi-thread control method.

[0004] According to one aspect of the present invention, a multi-thread control method is provided. The method includes:

[0005] During the process of the main thread parsing the first source code file, the main thread detects the sub-thread creation code and creates a sub-thread;

[0006] The sub-thread parses the second source code file associated with the sub-thread creation code;

[0007] Execute the parsed parsing instructions.

[0008] According to another aspect of the present invention, a multi-thread control apparatus is provided, which is characterized by including:

[0009] A thread creation module, configured to, during the process of the main thread parsing the first source code file, the main thread detects the sub-thread creation code and creates a sub-thread;

[0010] A sub-thread parsing module, configured to parse the second source code file associated with the sub-thread creation code through the sub-thread;

[0011] An instruction execution module, configured to execute the parsed parsing instructions.

[0012] According to another aspect of the present invention, an electronic device is provided. The electronic device includes:

[0013] At least one processor; and

[0014] A memory communicatively connected to the at least one processor; wherein,

[0015] The memory stores a computer program executable by the at least one processor. When executed by the at least one processor, the computer program enables the at least one processor to execute the multi-thread control method according to any embodiment of the present invention.

[0016] According to another aspect of the present invention, there is provided a computer-readable storage medium storing computer instructions for causing a processor to implement the multi-thread control method according to any embodiment of the present invention when executed.

[0017] According to another aspect of the present invention, there is provided a computer program product including a computer program which, when executed by a processor, implements the multi-thread control method according to any embodiment of the present invention.

[0018] In the technical solution of the embodiment of the present invention, during the process of parsing the first source code file in the main thread, if the sub-thread creation code is detected, a sub-thread is created, realizing the automatic creation of a sub-thread during the parsing process of the main thread. The sub-thread parses the second source code file associated with the sub-thread creation code and executes the parsed parsing instructions, enabling the sub-thread to separately parse the second source code file associated with the sub-thread creation code, thereby realizing the parallel parsing of the sub-thread and the main thread, improving the parsing efficiency, and thus improving the multi-thread control efficiency.

[0019] It should be understood that the content described in this part is not intended to identify the key or important features of the embodiments of the present invention, nor is it used to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention, and those of ordinary skill in the art can also obtain other drawings based on these drawings without creative efforts.

[0021] Figure 1a is a flowchart of a multi-thread control method provided according to Embodiment 1 of the present invention;

[0022] Figure 1b is a schematic structural diagram of a robot control system based on the multi-thread control method provided according to Embodiment 1 of the present invention;

[0023] Figure 2 is a flowchart of a multi-thread control method provided according to Embodiment 2 of the present invention;

[0024] Figure 3 It is a flowchart of a multi-thread control method provided in Embodiment 3 of the present invention;

[0025] Figure 4a It is an execution control flowchart of the main thread in a multi-thread control method provided in Embodiment 4 of the present invention;

[0026] Figure 4b It is an execution control flowchart of a child thread in a multi-thread control method provided in Embodiment 4 of the present invention;

[0027] Figure 5 It is a structural schematic diagram of a multi-thread control device provided in Embodiment 5 of the present invention;

[0028] Figure 6 It is a structural schematic diagram of an electronic device for implementing the multi-thread control method of the embodiments of the present invention. Detailed implementation manners

[0029] In order to enable those skilled in the art to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without making creative efforts shall fall within the protection scope of the present invention.

[0030] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily need to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present invention described here can be implemented in an order other than those illustrated or described here. In addition, the term "comprising" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0031] Embodiment 1

[0032] Figure 1a This is a flowchart of a multi-thread control method provided in Embodiment Ⅰ of the present invention. This embodiment is applicable to the case of implementing robot control based on the multi-thread control method. For the convenience of understanding, first, a robot control system based on the multi-thread control method involved in the embodiments of the present invention will be described in detail. Figure 1bThis is a schematic structural diagram of a robot control system based on a multi-thread control method provided in Embodiment 1 of the present invention. As Figure 1b shown, the robot control system includes a control teaching pendant module, a task scheduling module, a script parsing module, and a control module.

[0033] Among them, the control teaching pendant module is used to generate a source code file or generate an immediate control instruction, and send the source code file or the immediate control instruction to the task scheduling module. The number of source code files is at least one. Exemplarily, the source code files may include a first source code file, a second source code file, and a third source code file, etc. The immediate control instruction can implement controls such as starting, stopping, pausing, resuming, and debugging of the robot control system, and can also implement functions such as JOG control (jogging control), IO control (input / output control), or parameter configuration query of the robot. The immediate control instruction can be generated by means of touch screen, virtual keys, or writing source code.

[0034] The task scheduling module is used to receive the source code file or the immediate control instruction, send the source code file to the script parsing module to receive the parsing instruction generated by the script parser in the script parsing module according to the source code file, and implement the scheduling of the parsing instruction and the immediate control instruction. Scheduling the parsing instruction and the immediate control instruction can also be understood as that the task scheduling module sends the parsing instruction and the immediate control instruction to the control module or the task scheduling module. The task scheduling module can also be used to execute the instruction sent to the task scheduling module. Exemplarily, the instruction sent to the task scheduling module can be an instruction corresponding to the thread creation code, and the task scheduling module can create a child thread according to the instruction corresponding to the thread creation code and determine the script parser corresponding to the child thread in the script parsing module.

[0035] The script parsing module contains at least one script parser, and the number of script parsers can be determined according to the number of source code files to be parsed. The script parser is used to receive the source code file, parse the source code file, generate a parsing instruction, and send the parsing instruction to the task scheduling module. The parsing methods used by each script parser are the same, and each script parser can parse the source code file in parallel.

[0036] The control module is used to execute the instruction sent by the task scheduling module. Specifically, the control module can be used to perform motion control or input / output control on the robot. Exemplarily, the control module can implement robot movement trajectory planning or interpolation, and communication or interaction with physical devices such as motors and IO modules (input / output modules).

[0037] A robot control system based on a multi-thread control method provided by an embodiment of the present invention can achieve parallel parsing of multiple script parsing modules, improve parsing efficiency, and at the same time, the parsing methods used by each script parsing module are the same, reducing the complexity of script parsing module settings, improving the flexibility of script parsing module usage, and thus improving the efficiency and flexibility of multi-thread control.

[0038] The multi-thread control method can be executed by a multi-thread control device, which can be implemented in the form of hardware and / or software, and the multi-thread control device can be configured in an electronic device. As Figure 1a shown, the multi-thread control method includes:

[0039] S110. During the process of parsing the first source code file by the main thread, the main thread detects the sub-thread creation code and creates a sub-thread.

[0040] When a program starts, a process is created, and at the same time a thread also starts running immediately. This thread is usually called the main thread of the program. It can also be understood that the main thread is the thread created when the first source code file starts to be parsed. The first source code file refers to the source code file corresponding to the main thread. In the main thread, the first source code file can be parsed through the script parser corresponding to the main thread. The sub-thread creation code refers to the code for creating a sub-thread. A sub-thread can be created through the sub-thread creation code. A sub-thread refers to an independently running thread created outside the main thread. At least one sub-thread can be created through the main thread. The number of sub-threads is the same as the number of sub-thread creation codes in the first source code file. It can be understood that in the main thread, a sub-thread cancellation code can also be set to cancel the sub-thread. Exemplarily, the sub-thread cancellation code can be thread_destroy(thread_handle).

[0041] Specifically, the first source code file is parsed through the script parser corresponding to the main thread. During the process of parsing the first source code file, if the script parser corresponding to the main thread detects the sub-thread creation code, a sub-thread is created according to the sub-thread creation code, and after the creation is completed, the parsing of the first source code file continues, and at the same time, the sub-thread starts running after the creation is completed.

[0042] S120. Parse the second source code file associated with the sub-thread creation code through the sub-thread.

[0043] The second source code file refers to the source code file corresponding to the sub-thread. Each sub-thread corresponds to a second source code file. The second source code file and the first source code file can be edited using the same code programming language. The second source code file associated with the sub-thread creation code can be determined by the parameters in the sub-thread creation code. Specifically, the parameters of the sub-thread creation code can be the path of the source code file or the name of the source code file, etc. Exemplarily, the sub-thread creation code can be thread_handle = thread_create(" / path / to / thread / file.script").

[0044] Specifically, according to the parameters of the sub-thread creation code, determine the second source code file associated with the sub-thread creation code. The sub-thread parses the second source code file corresponding to the sub-thread creation code through the script parser corresponding to the sub-thread.

[0045] S130. Execute the parsed parsing instructions.

[0046] The parsing instructions refer to the instructions generated after parsing the source code file, and the source code file is the first source code file or the second source code file. Specifically, the parsed parsing instructions can be executed according to the priority of the thread where the parsing instructions are located. The priority of the thread where the parsing instructions are located can be set according to the actual situation. Among them, the priority of the thread where the parsing instructions are located refers to the priority between the sub-thread and the main thread. Exemplarily, the priority of the main thread is higher than that of the sub-thread, and the priority of the sub-thread created earlier is higher than that of the sub-thread created later. The parsed parsing instructions can also be executed according to the timing of obtaining the parsing instructions. The parsed parsing instructions can also be executed according to the instruction scheduling permission corresponding to the parsing instructions. According to the instruction scheduling permission, it can be determined whether the parsing instructions can be executed. Exemplarily, the parsing instructions with instruction scheduling permission can be executed, and the parsing instructions without instruction scheduling permission cannot be executed. The parsing instructions can obtain the instruction scheduling permission according to the set rules.

[0047] In the technical solution of the embodiment of the present invention, during the process of parsing the first source code file in the main thread, if the sub-thread creation code is detected, a sub-thread is created, realizing the automatic creation of a sub-thread during the parsing process in the main thread. The sub-thread parses the second source code file associated with the sub-thread creation code and executes the parsed parsing instructions, enabling the sub-thread to separately parse the second source code file associated with the sub-thread creation code, thereby realizing the parallel parsing of the sub-thread and the main thread, improving the parsing efficiency, and thus improving the multi-thread control efficiency.

[0048] Embodiment 2

[0049] Figure 2It is a flowchart of a multi-thread control method provided in the second embodiment of the present invention. On the basis of the above embodiment, this embodiment further includes: when the target thread detects the target code, the target thread skips parsing the target code, and the target code includes at least one of the following: the sub-thread creation code and the code corresponding to the serially executed instructions; wherein, the number of sub-threads is at least one, and the target thread includes: all threads other than one thread determined among the main thread and each sub-thread. As Figure 2 shown, the method includes:

[0050] S210. During the process of parsing the first source code file by the main thread, the main thread detects the sub-thread creation code and creates a sub-thread.

[0051] S220. Parse the second source code file associated with the sub-thread creation code through the sub-thread.

[0052] S230. When the target thread detects the target code, the target thread skips parsing the target code, and the target code includes at least one of the following: the sub-thread creation code and the code corresponding to the serially executed instructions; wherein, the number of sub-threads is at least one, and the target thread includes: all threads other than one thread determined among the main thread and each sub-thread.

[0053] The target thread refers to the thread that needs to skip parsing the code during the parsing process. Specifically, the target thread includes all threads other than one thread determined among the main thread and each sub-thread. The determined one thread refers to the thread that does not need to skip parsing the code during the parsing process. Exemplarily, during the process of the main thread parsing the first source code file, two sub-thread creation codes are detected, and the first sub-thread and the second sub-thread are respectively created. Then, when the determined one thread is the main thread, the target threads are the first sub-thread and the second sub-thread; when the determined one thread is the first sub-thread, the target threads are the main thread and the second sub-thread; when the determined one thread is the second sub-thread, the target threads are the main thread and the first sub-thread. The number of sub-threads is at least one, so the number of target threads is at least one. Specifically, the number of target threads is the sum of the number of sub-threads and the number of main threads minus one.

[0054] The target code refers to the code corresponding to instructions that cannot be executed in parallel. It can be understood that if the target code is parsed and executed in the target thread, it will cause uncertainty in the multi-thread control result. The target code includes at least one of the sub-thread creation code and the code corresponding to the serially executed instructions. The code corresponding to the serially executed instructions can include at least one of the action control instructions and the code corresponding to the instructions with obvious timing requirements. Among them, the action control instructions can include robot action control instructions. Exemplarily, the serially executed instructions can be the code corresponding to the linear motion instruction, or the code corresponding to the circular motion instruction, etc. It can be understood that, based on the scenario of controlling a robot by the multi-thread control method in the previous example, the target threads are the first sub-thread and the second sub-thread, the serially executed instruction in the first sub-thread is the linear motion instruction, and the serially executed instruction in the second sub-thread is the circular motion instruction. If the serially executed instructions in the first sub-thread and the second sub-thread are parsed and then executed, the robot will not be able to determine whether to execute the linear motion action or the circular motion action during the execution process, which will cause chaos in the robot's execution actions and affect the safety of robot control.

[0055] Specifically, during the parsing process of the script parser corresponding to the target thread, if the target code is detected, the script parser will skip parsing the target code. The script parser can detect the target code by looking up a table. Among them, the content of the table can be the target code or the identification information of the target code, and the script parser detects the target code through the identification information.

[0056] S240. Execute the parsed instructions obtained by parsing.

[0057] The technical solution of the embodiment of the present invention can skip parsing the target code when the target code is detected in the target thread, which can ensure that the target code is only parsed in one of the main thread and the sub-threads, reduce the occurrence probability of the situation where the target code is parsed in multiple threads and causes errors in multi-thread control, and thus improve the accuracy of multi-thread control.

[0058] Based on the above embodiment, the target thread includes: all the sub-threads.

[0059] Specifically, in this embodiment, the target code can be parsed only in the main thread, then the target thread is all the sub-threads, and each sub-thread skips parsing the target code when detecting the target code.

[0060] By determining the target thread as all the sub-threads, the target code can be parsed only in the main thread, ensuring that only the main thread can execute the parsed instructions after parsing the target code, thereby improving the accuracy of multi-thread control.

[0061] In addition, if the child thread is not the target thread, all the target codes in the first source code file and the second source code file cannot be parsed, resulting in a parsing error. At this time, the first source code file and the second source code file are not compatible with the method of parsing the target code only through the main thread.

[0062] Based on the above embodiments, the parsing instructions obtained by the main thread include at least one of the following: robot motion control instructions, input / output control instructions, and task scheduling control instructions. The parsing instructions obtained by the child thread include at least one of the following: input / output control instructions and task scheduling control instructions.

[0063] The robot motion control instruction refers to an instruction for controlling the motion of the robot. The robot motion control instruction includes at least one of instructions such as motion control instructions and setting instructions for motion control-related parameters. Exemplarily, the robot motion instruction may include motion control instructions such as linear motion instructions, circular motion instructions, and joint motion instructions; it may also be setting instructions for motion control-related parameters such as tool coordinate system setting instructions, user coordinate system setting instructions, and global speed setting instructions. The input / output control instruction refers to an instruction for controlling the input / output devices or interfaces of the robot, and can also be referred to as an IO control instruction. The task scheduling control instruction refers to an instruction executed in the task scheduling module. Exemplarily, the task scheduling control instruction may be an instruction for controlling a thread, such as waiting, program pause, and program resume; the task scheduling control instruction may also be an instruction for querying relevant parameters of a thread, such as a clock reading instruction.

[0064] Specifically, the parsing instructions obtained by the main thread may include at least one of robot motion control instructions, input / output control instructions, and task scheduling control instructions. Among them, the robot motion instruction belongs to the instructions executed serially. When the target thread is all child threads, the parsing instructions obtained by the child thread do not include robot motion execution instructions. Specifically, the parsing instructions obtained by the child thread include at least one of input / output control instructions and task scheduling control instructions.

[0065] By obtaining the robot motion control instruction only through the main thread parsing, the robot only executes the motion control instruction obtained by the main thread parsing, thereby avoiding the situation of incorrect robot motion caused by the robot simultaneously executing the motion instructions of the main thread and the child thread, and improving the accuracy of multi-thread control.

[0066] Embodiment III

[0067] Figure 3The flowchart of a multi-thread control method provided in Embodiment 3 of the present invention. Based on the above embodiments, the parsing instructions obtained by the execution are specifically: in the parsing instructions obtained by parsing, obtain the target instruction corresponding to the instruction scheduling permission and send it to the control module; pause the parsing operation of the thread corresponding to the non-scheduled instruction, and the parsing instructions obtained by parsing include the target instruction and the non-scheduled instruction; execute the target instruction through the control module; release the instruction scheduling permission, and establish a new correspondence between the instruction scheduling permission and the instruction, and return to execute the operation of obtaining the target instruction corresponding to the instruction scheduling permission in the parsing instructions obtained by parsing. As Figure 3 shown, the method includes:

[0068] S310. During the process of parsing the first source code file by the main thread, the main thread detects the sub-thread creation code and creates a sub-thread.

[0069] S320. Parse the second source code file associated with the sub-thread creation code through the sub-thread.

[0070] S330. In the parsing instructions obtained by parsing, obtain the target instruction corresponding to the instruction scheduling permission and send it to the control module.

[0071] The parsing instructions obtained by parsing refer to the parsing instructions obtained by parsing the first source code file or the second source code file. The parsing instructions obtained by parsing may include one instruction or multiple instructions. The number of instructions in the parsing instructions obtained by parsing can be set according to the actual situation. The instruction scheduling permission refers to the permission to send the parsing instructions obtained by parsing to the control module so that the control module executes the parsing instructions. The instruction scheduling permission can be allocated according to the priority between the main thread and the sub-thread, or the allocation rule of the instruction scheduling permission can be set according to the actual situation. The target instruction refers to the parsing instruction that obtains the instruction scheduling permission, or it can be understood that the target instruction refers to the parsing instruction corresponding to the instruction scheduling permission. At this time, a correspondence between the parsing instruction and the instruction scheduling permission can be established. The control module serially receives the target instruction, or it can be understood that the control module can only receive one target instruction at the same time.

[0072] Specifically, the parsing instructions obtained by parsing the first source code file or the parsing instructions obtained by parsing the second source code file respectively apply for the instruction scheduling permission, and the parsing instruction that obtains the instruction scheduling permission is determined as the target instruction, thereby establishing a correspondence between the parsing instruction and the instruction scheduling permission, and sending the target instruction to the control module.

[0073] Exemplarily, a first parsing instruction is obtained by parsing a first source code file in the main thread, and a second parsing instruction is obtained by parsing a second source code file in a sub-thread. If the first parsing instruction applies for instruction scheduling permission and the control module has no target instruction to receive, the first parsing instruction can obtain the instruction scheduling permission and be determined as the target instruction. At this time, a correspondence relationship is established between the first parsing instruction and the instruction scheduling permission, and the target instruction is sent to the control module; if the second parsing instruction applies for instruction scheduling permission and the control module has no target instruction to receive, the second parsing instruction can obtain the instruction scheduling permission and be determined as the target instruction. At this time, a correspondence relationship is established between the second parsing instruction and the instruction scheduling permission, and the target instruction is sent to the control module; if the first parsing instruction and the second parsing instruction apply for instruction scheduling permission at the same time and the control module has no target instruction to receive, the priorities of the first parsing instruction and the second parsing instruction are determined according to the priorities of the main thread and the sub-thread. The parsing instruction with the higher priority obtains the instruction scheduling permission and is determined as the target instruction. At this time, a correspondence relationship is established between the parsing instruction with the higher priority and the instruction scheduling permission, and the target instruction is sent to the control module; if the first parsing instruction applies for instruction scheduling permission and the control module has a target instruction to receive, the first parsing instruction continuously waits to apply for instruction scheduling permission until it can obtain the instruction scheduling permission and is determined as the target instruction. At this time, a correspondence relationship is established between the first parsing instruction and the instruction scheduling permission, and the target instruction is sent to the control module; if the second parsing instruction applies for instruction scheduling permission and the control module has a target instruction to receive, the second parsing instruction applies for instruction scheduling permission every threshold time until it can obtain the instruction scheduling permission and is determined as the target instruction. At this time, a correspondence relationship is established between the second parsing instruction and the instruction scheduling permission, and the target instruction is sent to the control module, where the threshold time can be set according to the actual situation.

[0074] S340. Pause the parsing operation of the thread corresponding to the non-scheduled instruction, where the obtained parsing instruction includes the target instruction and the non-scheduled instruction.

[0075] The non-scheduled instruction refers to the parsing instruction that has not obtained the instruction scheduling permission. Specifically, among the obtained parsing instructions, the parsing instruction that obtains the instruction scheduling permission is determined as the target instruction, and the parsing instruction that has not obtained the instruction permission is determined as the non-scheduled instruction. The thread where the non-scheduled instruction is located will pause the parsing operation until the non-scheduled instruction obtains the instruction scheduling permission and is sent to the control module, and then the parsing operation is resumed.

[0076] S350. Execute the target instruction through the control module

[0077] Specifically, after receiving the target instruction, the control module executes the target instruction. Among them, the control module executes the target instruction serially.

[0078] S360. Release the instruction scheduling permission, establish the correspondence between the new instruction scheduling permission and the instruction, and return to execute the operation of obtaining the target instruction corresponding to the instruction scheduling permission in the parsed instruction obtained by parsing.

[0079] The correspondence between the new instruction scheduling permission and the instruction refers to the correspondence between the instruction scheduling permission and the instruction newly formed after the non-scheduled instruction obtains the instruction scheduling permission. Specifically, after the control module executes the target instruction, the target instruction releases the instruction scheduling permission, so that the control module can receive a new target instruction. After releasing the instruction scheduling permission, the non-scheduled instruction can obtain the instruction scheduling permission to establish the correspondence between the new instruction scheduling permission and the instruction, and return to step S330 until all the parsed instructions are sent to the control module.

[0080] Optionally, it can also be the operation that the target instruction releases the instruction scheduling permission after being sent and establishes the target instruction corresponding to the new instruction scheduling permission, which can improve the efficiency of sending the target instruction to the control module, thereby improving the efficiency of the control module executing the target instruction.

[0081] The technical solution of the embodiment of the present invention can serially send the parsed instructions to the control module in a certain order by obtaining the target instruction corresponding to the instruction scheduling permission in the parsed instruction obtained by parsing and sending it to the control module, avoiding congestion during the sending of the target instruction, improving the sending efficiency of the target instruction, and thus improving the accuracy of the control module executing the target instruction. By pausing the parsing operation of the thread corresponding to the non-scheduled instruction, it can ensure that the non-scheduled instruction obtains the instruction scheduling permission in time and improve the efficiency of sending the non-scheduled instruction to the control module.

[0082] On the basis of the above embodiment, it further includes: obtaining an immediate control instruction; the establishing the correspondence between the new instruction scheduling permission and the instruction includes: establishing the correspondence between the instruction scheduling permission and the immediate control instruction.

[0083] The immediate control instruction refers to an instruction for controlling a thread during the running of the thread. Through the immediate control instruction, controls such as starting, stopping, pausing, resuming, and debugging of the thread can be realized. By establishing the correspondence between the new instruction scheduling permission and the immediate control instruction, the immediate control instruction that obtains the instruction scheduling permission can be determined.

[0084] Specifically, during the operation of each thread, an immediate control instruction is obtained, and according to the immediate control instruction, a corresponding relationship is established between the instruction scheduling authority and the immediate control instruction. The corresponding relationship between the instruction scheduling authority and the immediate control instruction can be established according to the priority between the immediate control instruction and the parsed instruction obtained by parsing. Exemplarily, on the basis of the foregoing example, the priority of the immediate control instruction is higher than that of the parsed instruction obtained by parsing. When the immediate control instruction is obtained, if the control module has no target instruction to receive, the immediate control instruction obtains the instruction scheduling authority, and a corresponding relationship is established between the instruction scheduling authority and the immediate control instruction; if the control module has a target instruction to receive, after the control module finishes receiving, the immediate control instruction obtains the instruction scheduling authority, and a corresponding relationship is established between the instruction scheduling authority and the immediate control instruction; if the immediate control instruction and the parsed instruction obtained by parsing apply for the instruction scheduling authority at the same time, the immediate control instruction preferentially obtains the instruction scheduling authority, and a corresponding relationship is established between the instruction scheduling authority and the immediate control instruction.

[0085] By obtaining the immediate control instruction and establishing the corresponding relationship between the instruction scheduling authority and the immediate control instruction, it is ensured that the immediate control instruction can be preferentially executed, the execution efficiency of the immediate control instruction is improved, and each thread can respond promptly to the immediate control instruction.

[0086] On the basis of the above embodiments, the parsed instructions obtained by the main thread parsing and the parsed instructions obtained by the sub-thread parsing can be executed independently of each other.

[0087] Independent execution means that there is no dependency relationship between the parsed instructions obtained by the main thread parsing and the parsed instructions obtained by the sub-thread parsing, and they can be executed separately. It can also be understood that the first source code file and the second source code file are independent job files.

[0088] By the parsed instructions obtained by the main thread parsing and the parsed instructions obtained by the sub-thread parsing being executed independently of each other, the dependency relationship between the main thread and the sub-thread is reduced, and the parsed instructions obtained by the sub-thread parsing can be executed in the main thread, thereby improving the flexibility of multi-thread control.

[0089] It can be understood that in the main thread or the sub-thread, the parsed instructions obtained by parsing need to be executed in the order of parsing in the thread.

[0090] Further, the parsing instructions obtained by the main thread and the parsing instructions obtained by the sub-thread can be executed independently of each other, so that the first source code file can run as the second source code in the sub-thread, and the second source code file can also run as the first source code file in the main thread. At the same time, the parsing methods of the first source code file and the second source code file are the same, so there is no need to reset the parsing method for the second source code file, which simplifies the setting complexity of the script parsers of each thread, and further improves the flexibility of multi-thread control.

[0091] Embodiment 4

[0092] Figure 4a The figure is the execution control flow chart of the main thread in a multi-thread control method provided by Embodiment 4 of the present invention. The execution control flow chart provided by the embodiment of the present invention is applicable to the situation of implementing robot control, and can be applied to a robot control system based on the multi-thread control method. As Figure 4a shown, the execution control flow of the main thread is as follows:

[0093] When the system starts running, initialize the robot control system. The task scheduling module determines whether there is an immediate control instruction issued by the control teaching device module. If there is an immediate control instruction, receive the immediate control instruction. The immediate control instruction applies for instruction scheduling permission. After the immediate control instruction obtains the instruction scheduling permission, the task scheduling module sends the immediate control instruction to the control module, and the control module executes the immediate control instruction. At the same time, the immediate control instruction releases the instruction scheduling permission. If there is no immediate control instruction, the task scheduling module determines whether there is a first source code file.

[0094] If there is a first source code file, the script parser corresponding to the main thread parses the first source code file to obtain parsing instructions. The parsing instructions apply for instruction scheduling permission. After the parsing instructions obtain the instruction scheduling permission, the task scheduling module sends the parsing instructions to the control module, and the control module executes the parsing instructions. During the parsing of the first source code, it is judged whether there are parsing instructions obtained by parsing the sub-thread creation code. If so, create a sub-thread according to the parsing instructions obtained by parsing the sub-thread creation code and run the sub-thread. After the creation is completed, the parsing instructions obtained by parsing the sub-thread creation code release the instruction scheduling permission; if not, the parsing instructions directly release the instruction scheduling permission.

[0095] After releasing the instruction scheduling permission, the robot synchronizes the state of the robot according to the instructions executed by the control module, and returns to the step of judging whether there is an immediate control instruction.

[0096] Optionally, the child thread creation code can be thread_handle = thread_create(" / path / to / thread / file.script"). A return value can be set in the child thread creation code. The return value can be a thread handle, which is used to represent the state of the thread. Exemplarily, the state of the thread can include created, executing, and execution completed, etc. Control operations such as cancellation, synchronization, or suspension of the thread can be achieved through the thread handle. Exemplarily, when the creation of the child thread fails (the path of the second source code file cannot be loaded properly or the number of child threads exceeds the limit), an error code -1 is returned as the thread handle, otherwise a non-negative number is returned as the thread handle.

[0097] Optionally, a child thread cancellation code can be set in the first source code file to cancel the child thread. Exemplarily, the child thread cancellation code can be thread_destroy(thread_handle). After executing the parsing instruction obtained by parsing the child thread cancellation code, the child thread corresponding to the child thread cancellation code will immediately terminate its execution, and the information associated with the child thread will be retrieved by the task scheduling module. If the child thread corresponding to the child thread cancellation code does not exist, an error handling will be performed. The parameter in the child thread cancellation code can be the handle returned when the parsing instruction obtained by parsing the child thread creation code is executed, or it can be the path or name of the source code file, etc.

[0098] Optionally, the task scheduling module can establish a child thread list for storing the parsing instructions generated after parsing the second source file code in the child thread. Initially, it is empty and will be cleared after the program execution ends. When the script parser parses a child thread creation instruction, the task scheduling module will create a child thread and add it to the thread list. At the same time, another script parser will be created and associated with the thread handle.

[0099] Optionally, for instructions with mandatory execution timing, synchronization between the main thread and the child thread can be achieved through synchronization code in the main thread. Exemplarily, the synchronization code can be: thread_join(thread_handle), where the parameter of the synchronization code can be the handle of the child thread. When the main thread parses the synchronization code, it needs to query the status of the child thread specified by the handle in real time until the status of the child thread is execution completed before continuing to parse.

[0100] Optionally, for the convenience of data interaction between multiple threads, global variables can be declared in the source code file using the global keyword. Global variables support multiple basic data types such as strings, arrays, floating-point numbers, and integers, and global variables are stored in a shared memory area accessible to each thread. Since each thread involves accessing global variables, protection for critical regions is provided for global variables. It can be understood that when any thread accesses a global variable among all threads, all other threads will be in a waiting state until the thread accessing the global variable completes the access and exits the critical region. Exemplarily, the code for providing protection for critical regions for global variables can be: thread_enter_critical(), which is used to enter the critical region, that is, to access the global variable, and thread_exit_critical(), which is used to exit the critical region, that is, to complete the access to the global variable. Since entering the critical region is equivalent to exclusive running permission, to ensure that other threads can run normally, it is required that the instructions executed during the entry and exit of the critical region be as short as possible.

[0101] Figure 4b It is a flowchart for controlling the execution of a child thread in a multi-thread control method provided in Embodiment 4 of the present invention. As Figure 4b shown, the execution control process of the child thread is as follows:

[0102] After the child thread is created, the child thread is initialized. First, the task scheduling module determines whether there is an immediate control instruction to externally terminate or pause the control of the child thread. If so, the child thread ends. If not, the second source code file is parsed according to the script parser corresponding to the child thread to generate parsing instructions. The parsing instructions apply for instruction scheduling permission. After obtaining the instruction scheduling permission, the task scheduling module sends the instruction scheduling permission to the control module, and at the same time, the parsing instructions release the instruction scheduling permission. The task scheduling module determines whether the child thread has completed execution, which can also be understood as determining whether all the parsing instructions generated by parsing the second source code file have been sent to the control module. If so, the child thread ends. If not, the child thread will return to the step of determining whether there is an immediate control instruction to externally terminate or pause the control of the child thread.

[0103] The technical solution of the embodiment of the present invention creates a child thread if a child thread creation code is detected during the parsing of the first source code file in the main thread, realizing the automatic creation of a child thread during the parsing of the main thread. The child thread parses the second source code file associated with the child thread creation code and executes the obtained parsing instructions, enabling the child thread to separately parse the second source code file associated with the child thread creation code, thereby realizing the parallel parsing of the child thread and the main thread, improving the parsing efficiency, and thus improving the multi-thread control efficiency.

[0104] Embodiment 5

[0105] Figure 5 This is a schematic structural diagram of a multi-thread control device provided in Embodiment 5 of the present invention. As Figure 5 shown, the device includes: a thread creation module 501, a sub-thread parsing module 502, and an instruction execution module 503.

[0106] Among them, the thread creation module 501 is used to create a sub-thread when the main thread detects the sub-thread creation code during the process of parsing the first source code file through the main thread;

[0107] The sub-thread parsing module 502 is used to parse the second source code file associated with the sub-thread creation code through the sub-thread;

[0108] The instruction execution module 503 is used to execute the parsed instructions.

[0109] The technical solution of the embodiment of the present invention creates a sub-thread when the main thread detects the sub-thread creation code during the process of parsing the first source code file, realizing the automatic creation of a sub-thread during the parsing process of the main thread. The sub-thread parses the second source code file associated with the sub-thread creation code and executes the parsed instructions, enabling the sub-thread to separately parse the second source code file associated with the sub-thread creation code, thereby realizing the parallel parsing of the sub-thread and the main thread, improving the parsing efficiency, and thus improving the multi-thread control efficiency.

[0110] Optionally, the device further includes:

[0111] A code skipping module, which is used to skip parsing the target code through the target thread when the target thread detects the target code. The target code includes at least one of the following: the sub-thread creation code and the code corresponding to the serially executed instructions; wherein, the number of sub-threads is at least one, and the target thread includes: all threads other than one thread determined from the main thread and each sub-thread.

[0112] Optionally, the target thread includes: all the sub-threads.

[0113] Optionally, the instruction execution module 503 includes:

[0114] A target instruction sending unit, which is used to obtain the target instruction corresponding to the instruction scheduling permission in the parsed instructions and send it to the control module;

[0115] A parsing pause unit, which is used to pause the parsing operation of the thread corresponding to the non-scheduled instruction. The parsed instructions include the target instruction and the non-scheduled instruction;

[0116] A target instruction execution unit for executing the target instruction through the control module;

[0117] A correspondence establishing unit for releasing the instruction scheduling permission and establishing a correspondence between the new instruction scheduling permission and the instruction, and returning the operation of obtaining the target instruction corresponding to the instruction scheduling permission in the parsed instruction obtained by parsing.

[0118] Optionally, the apparatus further includes:

[0119] An immediate control instruction acquisition module for acquiring an immediate control instruction;

[0120] The correspondence establishing unit is specifically configured to:

[0121] Establish a correspondence between the instruction scheduling permission and the immediate control instruction.

[0122] Optionally, the parsed instructions obtained by the main thread and the parsed instructions obtained by the sub-thread can be executed independently of each other.

[0123] Optionally, the parsed instructions obtained by the main thread include at least one of the following: a robot motion control instruction, an input / output control instruction, and a task scheduling control instruction, and the parsed instructions obtained by the sub-thread include at least one of the following: an input / output control instruction and a task scheduling control instruction.

[0124] The multi-thread control device provided by the embodiments of the present invention can execute the multi-thread control method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0125] Embodiment Six

[0126] Figure 6 FIG. shows a schematic structural diagram of an electronic device 10 that can be used to implement the embodiments of the present invention. The electronic device is intended to represent various forms of digital computers, such as, a laptop computer, a desktop computer, a workbench, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as, a personal digital processor, a cellular phone, a smart phone, a wearable device (such as a helmet, glasses, a watch, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present invention described herein and / or claimed.

[0127] As Figure 6As shown, the electronic device 10 includes at least one processor 11 and a memory communicatively connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc. Among them, the memory stores a computer program executable by the at least one processor. The processor 11 can execute various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 into the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0128] Multiple components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disc, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0129] The processor 11 can be various general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include but are not limited to a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the multi-thread control method.

[0130] In some embodiments, the multi-thread control method can be implemented as a computer program, which is tangibly included in a computer-readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the multi-thread control method described above can be executed. Alternatively, in other embodiments, the processor 11 can be configured to execute the multi-thread control method in any other appropriate way (e.g., by means of firmware).

[0131] The various embodiments of the systems and techniques described above in this specification can be implemented in digital electronic circuitry, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems-on-chip (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include: being implemented in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which may be a special-purpose or general-purpose programmable processor that receives data and instructions from, and transmits data and instructions to, a storage system, at least one input device, and at least one output device.

[0132] The computer programs for implementing the methods of the present invention can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer programs, when executed by the processor, cause the functions / operations specified in the flowchart and / or block diagram to be implemented. The computer programs can be executed entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.

[0133] In the context of the present invention, a computer-readable storage medium can be a tangible medium that can contain or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. The computer-readable storage medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, the computer-readable storage medium can be a machine-readable signal medium. More specific examples of the machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0134] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or a trackball) through which the user can provide input to the electronic device. Other kinds of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0135] The systems and techniques described herein can be implemented in a computing system including backend components (e.g., as a data server), or a computing system including middleware components (e.g., an application server), or a computing system including frontend components (e.g., a user computer having a graphical user interface or a web browser through which the user can interact with an implementation of the systems and techniques described herein), or a computing system including any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected to each other by digital data communication in any form or medium (e.g., a communication network). Examples of communication networks include: local area network (LAN), wide area network (WAN), blockchain network, and the Internet.

[0136] A computing system can include a client and a server. The client and the server are generally far from each other and usually interact through a communication network. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or a cloud host, which is a host product in the cloud computing service system and solves the defects of difficult management and weak business scalability existing in traditional physical hosts and VPS (Virtual Private Server) services.

[0137] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps recited in the present invention can be executed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved, and no limitation is made herein.

[0138] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A multi-thread control method, characterized in that, including: During the process of parsing the first source code file by the main thread, the main thread detects the sub-thread creation code and creates a sub-thread; Parse the second source code file associated with the sub-thread creation code through the sub-thread; wherein, the second source code file associated with the sub-thread creation code is determined by the parameters in the sub-thread creation code; the parameters in the sub-thread creation code include the path or name of the source code file; the sub-thread parses the second source code file corresponding to the sub-thread creation code through the script parser corresponding to the sub-thread, and the sub-thread can independently parse the second source code file associated with the sub-thread creation code; When the target thread detects the target code, skip parsing the target code through the target thread; the target code refers to the code corresponding to the instructions that cannot be executed in parallel, and the target code includes at least one of the following: the sub-thread creation code and the code corresponding to the serially executed instructions, and the code corresponding to the serially executed instructions includes at least one of the action control instructions and the code corresponding to the instructions with obvious timing requirements; Wherein, the target thread refers to the thread that needs to perform skip-parsing processing on the code during the parsing process; the number of sub-threads is at least one, and the target threads include: all threads other than one thread determined among the main thread and each sub-thread; the determined one thread refers to the thread that does not need to perform skip-parsing processing on the code during the parsing process; Execute the parsed parsing instructions.

2. The method according to claim 1, characterized in that, The execution of the parsed parsing instructions includes: In the parsed parsing instructions, obtain the target instruction corresponding to the instruction scheduling permission and send it to the control module; Suspend the parsing operation of the thread corresponding to the non-scheduled instruction, and the parsed parsing instructions include the target instruction and the non-scheduled instruction; Execute the target instruction through the control module; Release the instruction scheduling permission, establish a new correspondence between the instruction scheduling permission and the instruction, and return to the operation of obtaining the target instruction corresponding to the instruction scheduling permission in the parsed parsing instructions.

3. The method according to claim 1, wherein It also includes: Obtain the immediate control instruction; Establishing a new correspondence between the instruction scheduling permission and the instruction includes: Establish a correspondence between the instruction scheduling permission and the immediate control instruction; wherein, the immediate control instruction refers to the instruction for controlling the thread during the thread operation.

4. The method according to claim 1, wherein The parsing instructions obtained by the main thread and the parsing instructions obtained by the sub-thread can be executed independently of each other.

5. The method according to claim 1, characterized in that, The parsing instructions obtained by the main thread include at least one of the following: robot action control instructions, input / output control instructions, and task scheduling control instructions, and the parsing instructions obtained by the sub-thread include at least one of the following: input / output control instructions and task scheduling control instructions.

6. A multi-thread control device, characterized in that, including: A thread creation module, which is used to create a sub-thread when the main thread detects the sub-thread creation code during the process of parsing the first source code file by the main thread; A sub-thread parsing module, which is used to parse a second source code file associated with the sub-thread creation code through a sub-thread; wherein, the second source code file associated with the sub-thread creation code is determined by parameters in the sub-thread creation code; the parameters in the sub-thread creation code include the path of the source code file or the name of the source code file; the sub-thread parses the second source code file corresponding to the sub-thread creation code through a script parser corresponding to the sub-thread, and the sub-thread can independently parse the second source code file associated with the sub-thread creation code; A code skipping module, which is used to skip parsing the target code through the target thread when the target thread detects the target code; the target code refers to the code corresponding to instructions that cannot be executed in parallel, and the target code includes at least one of the following: the sub-thread creation code and the code corresponding to instructions executed serially, and the code corresponding to instructions executed serially includes at least one of action control instructions and the code corresponding to instructions with obvious timing requirements; wherein, the target thread refers to a thread that needs to perform skip parsing processing on the code during the parsing process, and the number of sub-threads is at least one, and the target threads include: all threads other than one thread determined among the main thread and each sub-thread; the determined one thread refers to a thread that does not need to perform skip parsing processing on the code during the parsing process; An instruction execution module, which is used to execute the parsed parsing instructions.

7. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the multi-thread control method according to any one of claims 1-5.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions, and the computer instructions are used to implement the multi-thread control method according to any one of claims 1-5 when executed by a processor.

Citation Information

Patent Citations

  • Driving program loading method and device

    CN104360889A

  • File execution method and device

    CN114201266A