A parallel lock-free programmable script design method and device

By defining private pointer variables for worker threads in load balancing devices and using memory barriers for lock-free replacement, the lock competition problem between configuration threads and worker threads is solved, improving system performance and script operation efficiency.

CN118051324BActive Publication Date: 2025-02-18TMLAKE (BEIJING) TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311255751.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-27
Publication Date
2025-02-18
Estimated Expiration
2043-09-27

AI Technical Summary

Technical Problem

In existing load balancing devices, configuration threads and worker threads will compete for lock resources when interacting with data, resulting in blockage of configuration updates and inefficient lock operation.

Method used

By defining the worker's private pointer variable, it is registered to the pointer array of the configuration thread when the worker starts, and using the memory barrier to replace the script content under lock-free conditions to avoid lock competition.

Benefits of technology

It solves the problem that multi-threaded competition for lock resources affects configuration updates, improves thread operation performance and script operation efficiency, and avoids the inefficiency of lock operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118051324B_ABST
    Figure CN118051324B_ABST
Patent Text Reader

Abstract

The present invention discloses a parallel lock-free programmable script design method and device, which are applied to the field of Internet technology. The method includes: thread initialization configuration: defining the private pointer variable of the working thread according to the thread structure and the pointer structure, and initializing and configuring the working thread and the configuration thread based on the private pointer variable; thread running and obtaining script data: running the working thread, obtaining and executing the script data through the private pointer variable; script data replacement: the configuration thread receives new script data and updates the script pointer variable; wherein the thread structure includes thread number, thread category and thread quantity, the thread category includes working thread and configuration thread, and the pointer structure includes private pointer variable and script pointer variable, so as to improve the performance of thread running and the efficiency of execution.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of Internet technology, and more specifically, to a parallel lock-free programmable script design method and device. Background Art

[0002] In a load balancing device, users hope to customize the packet forwarding path, packet protocol header options, or data content of accessing the virtual server by mounting a custom script on the virtual server. In this case, the best option is to quickly provide users with programmable scripts, allowing users to customize the functions they want through simple script configuration.

[0003] In commonly used load balancing devices, there is a configuration thread and N worker threads. The configuration thread is responsible for receiving the user's configuration on the WEB interface or CLI (command line), and then passing it to the worker thread. The worker thread completes the processing of the data packet (discarding or forwarding) according to the user's configuration.

[0004] Because it involves the interaction of data between the configuration thread and the worker thread at runtime, in order to ensure the consistency of the interaction data, the general practice is that after receiving the script data sent by the WEB end or CLI, the configuration thread first checks the correctness of the script content, then adds a global lock, obtains the global lock, and then replaces the script files on the virtual server one by one, and finally releases the lock. When the worker thread needs to execute the script, it first obtains this global lock. After obtaining the global lock, it can get the executable script on the virtual server, and then releases the global lock after executing the script. In this way, the configuration thread and the worker thread will compete for lock resources due to script updates. The worker threads will use read locks. If there are many worker threads and the tasks are busy, the worker threads may keep holding the read locks without releasing them, causing the write locks applied by the configuration thread to wait and affect the configuration update. Or another way is to let each worker thread have a script configuration lock. When the worker thread wants to execute the script, it adds its own script configuration lock, but this will bring another problem, that is, when the configuration thread is updated, it must first obtain all lock resources before replacing them one by one, because obtaining the lock may fail. No matter which locking method is used, it will prevent the worker thread from executing the script, and the locking operation is inefficient.

[0005] To sum up, it is necessary to introduce a new method and device to replace configuration content such as scripts in a lock-free manner, determine whether the script content is in use by whether the private pointer of the working thread points to the new script content, and replace and release the old script content space based on the judgment result, so as to solve the technical problems in the prior art of multi-thread competition for lock resources affecting configuration updates, and failure to obtain locks when configuration threads are updated, thereby improving the performance and execution efficiency of thread running, as well as the efficiency of operations on script content. Summary of the invention

[0006] In response to the technical problems mentioned above, the present invention provides a parallel lock-free programmable script design method and device, which defines a private pointer variable of a working thread, and registers the private pointer variable of each working thread in the pointer array of a configuration thread when the working thread is started. Based on this, the script data is obtained and executed when the working thread is running, and a memory barrier is added. The configuration thread and the memory barrier are used to update the new script data and release the memory space of the old script data. This completes the lock-free replacement method, and determines whether the script content is in use by whether the private pointer of the working thread points to the new script content. The old script content space is replaced and released according to the judgment result, which solves the technical problems in the prior art of multi-thread competition for lock resources affecting configuration updates and failure to obtain locks when the configuration thread is updated, thereby improving the thread running performance and execution efficiency, as well as the operation efficiency of the script content.

[0007] The present invention provides a parallel lock-free programmable script design method, the method comprising:

[0008] S101, thread initialization configuration: define the private pointer variable of the working thread according to the thread structure and the pointer structure, and initialize and configure the working thread and the configuration thread based on the private pointer variable; S102, thread running and obtaining script data: run the working thread, obtain and execute the script data through the private pointer variable; S103, script data replacement: the configuration thread receives new script data, and updates the script pointer variable; wherein the thread structure includes a thread number, a thread category and a thread quantity, the thread category includes the working thread and the configuration thread, and the pointer structure includes the private pointer variable and the script pointer variable.

[0009] As described above, the step of initializing and configuring the working thread and the configuration thread based on the private pointer variable includes: constructing a thread stack according to the thread structure and the pointer structure, and defining private pointer variables for all working threads in the thread stack according to the thread number and the thread category, and creating a pointer array for the configuration thread; starting the working thread, and registering the addresses of the private pointer variables corresponding to all working threads in the thread stack into the pointer array;

[0010] Here, assuming that the thread number is bh, and the number of working threads in the thread stack is n, then the pointer array is array[bh], bh is less than or equal to n, and n is an integer greater than 1.

[0011] Optionally, in step S102, before the thread runs and obtains the script data, it also includes a script data processing step, specifically: the configuration thread receives the script data, performs a syntax check on the script data, and allocates memory space; stores the script data that has passed the syntax check in the memory space; obtains the script pointer variable, and points the script pointer variable to the memory space corresponding to the script data.

[0012] As described above, the S102, thread running and obtaining script data: running the working thread, the step of obtaining and executing the script data through the private pointer variable includes: running the working thread, the working thread, based on the script pointer variable, uses the private pointer variable corresponding to the working thread to point to the first address of the memory space of the script data, and adds a memory barrier for the script data; according to the first address, the working thread uses the corresponding private pointer variable to obtain the script data from the memory space in sequence; executes the script data, returns the execution result through the working thread, and adds the memory barrier to the execution result, and sets the private pointer variable of the working thread to a null value; wherein the memory barrier is a control instruction for CPU out-of-order execution, which is used to prevent multi-thread out-of-order execution when multiple threads are executed simultaneously, thereby ensuring the global consistency of the script data.

[0013] As described above, step S103, script data replacement: the configuration thread receives new script data and updates the script pointer variable, specifically: the configuration thread receives new script data, performs syntax check on the new script data, and allocates new memory space; stores the new script data after syntax check into the new memory space, and obtains the address of the new memory space; points the script pointer variable to the new memory space corresponding to the new script data, and adds a memory barrier.

[0014] As described above, step S103, script data replacement: the step of the configuration thread receiving new script data, and updating the script pointer variable also includes the step of releasing the script data, specifically: adding a memory barrier for the working thread, and based on the pointer array array[bh], the configuration thread obtains and traverses the private pointer variables of all the working threads according to the thread number of the working thread, and releases the memory space of the script data according to the traversal result. If the private pointer variables of all the working threads are null values ​​or point to the new memory space corresponding to the new script data, the grace period of the working thread ends, and a memory barrier is added to release the memory space of the script data corresponding to the private pointer variable of the working thread.

[0015] Accordingly, the present invention also provides a parallel lock-free programmable script design device, the device comprising a thread initial configuration unit, a script data execution unit and a script data replacement unit;

[0016] Among them, the thread initial configuration unit is used for thread initialization configuration: according to the thread structure and the pointer structure, the private pointer variable of the working thread is defined, and the working thread and the configuration thread are initialized and configured based on the private pointer variable; the script data execution unit is used to run the thread and obtain the script data: run the working thread, obtain the script data through the private pointer variable, and execute the script data; the script data replacement unit is used for script data replacement: the configuration thread receives new script data and updates the script pointer variable; the thread structure includes the thread number, thread category and thread quantity, the thread category includes the working thread and the configuration thread, and the pointer structure includes the private pointer variable and the script pointer variable.

[0017] As described above, the script data execution unit is also used to process script data, and the specific steps are: the configuration thread receives the script data, performs syntax check on the script data, and allocates memory space; stores the script data that has passed the syntax check in the memory space; obtains the script pointer variable, and points the script pointer variable to the memory space corresponding to the script data.

[0018] As described above, the script data replacement unit is also used to release script data, and the specific steps are: adding a memory barrier for the working thread, and based on the pointer array array[bh], the configuration thread obtains and traverses the private pointer variables of all the working threads according to the thread number of the working thread, and releases the memory space of the script data according to the traversal result. If the private pointer variable of the working thread is a null value or points to a new memory space corresponding to the new script data, the grace period of the working thread ends, and a memory barrier is added to release the memory space of the script data corresponding to the private pointer variable of the working thread.

[0019] By applying the above technical scheme, the present invention realizes that by defining the private pointer variable of the working thread, the private pointer variable of each working thread is registered in the pointer array of the configuration thread when the working thread is started, based on this, the script data is obtained and executed when the working thread is running and a memory barrier is added, and the configuration thread and the memory barrier are used to update the new script data and release the memory space of the old script data, and the lock-free replacement is completed. Whether the script content is in use is determined by whether the private pointer of the working thread points to the new script content, and the old script content space is replaced and released according to the result of the judgment, which solves the technical problems in the prior art that multi-thread competition for lock resources affects configuration updates, and the failure to obtain locks when the configuration thread is updated, and improves the performance and execution efficiency of the thread operation, as well as the efficiency of operating the script content. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0021] Figure 1 A schematic flow chart of a parallel lock-free programmable script design method proposed in an embodiment of the present invention is shown;

[0022] Figure 2 A schematic diagram of a thread running process of a parallel lock-free programmable script design method proposed in an embodiment of the present invention is shown;

[0023] Figure 3 A schematic diagram of a script data replacement process of a parallel lock-free programmable script design method proposed in an embodiment of the present invention is shown;

[0024] Figure 4 A structural schematic diagram of a parallel lock-free programmable script design device proposed in an embodiment of the present invention is shown. DETAILED DESCRIPTION

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

[0026] The present invention provides a parallel lock-free programmable script design method, such as Figure 1 As shown, the method comprises the following steps:

[0027] S101, thread initialization configuration: defining a private pointer variable of a working thread according to a thread structure and a pointer structure, and initializing and configuring the working thread and the configuration thread based on the private pointer variable;

[0028] The thread structure includes a thread number, a thread category and a thread quantity, the thread category includes a working thread and a configuration thread, and the pointer structure includes a private pointer variable and a script pointer variable.

[0029] In this embodiment, in step S101, the step of initializing and configuring the working thread and the configuration thread based on the private pointer variable includes:

[0030] According to the thread structure and the pointer structure, a thread stack is constructed, and according to the thread number and the thread category, private pointer variables are defined for all working threads in the thread stack respectively, and a pointer array is created for the configuration line;

[0031] Starting the working thread, and registering the addresses of the private pointer variables corresponding to all the working threads in the thread stack into the pointer array;

[0032] Here, assuming that the thread number is bh, and the number of working threads in the thread stack is n, then the pointer array is array[bh], bh is less than or equal to n, and n is an integer greater than 1.

[0033] It should be noted that in a specific application scenario, a thread stack contains multiple working thread pools and one configuration thread pool, and the ratio of the two is N:1. When the working thread and the configuration thread are initialized and configured based on the private pointer variable, it is necessary to define a private pointer variable for each of the working threads in the thread stack. The type of the private pointer variable is void type, and each of the working threads has a globally unique thread number. When the working thread is started, the working thread registers the address of the corresponding private pointer variable to the pointer array array[bh] of the configuration thread. The subscript of the pointer array is the thread number, and the type of the pointer array is void type, so that the configuration thread can access the private pointer variable of each of the working threads according to the thread number, and then determine whether the working thread is using the script.

[0034] S102, thread running and obtaining script data: running the working thread, obtaining and executing the script data through the private pointer variable.

[0035] Optionally, in step S102 of this embodiment, before the thread runs and obtains the script data, a script data processing step is further included, specifically:

[0036] The configuration thread receives the script data, performs syntax check on the script data, and allocates memory space;

[0037] storing the script data that has undergone syntax checking into the memory space;

[0038] The script pointer variable is obtained, and the script pointer variable is pointed to the memory space corresponding to the script data.

[0039] In order to ensure that the data after the worker thread obtains the script data and before returning the execution result is globally visible and consistent, in this embodiment, the step of S102, thread running and obtaining script data: running the worker thread, and obtaining and executing the script data through the private pointer variable includes:

[0040] Running the working thread, wherein the working thread uses a private pointer variable corresponding to the working thread to point to the first address of the memory space of the script data based on the script pointer variable, and adds a memory barrier for the script data;

[0041] According to the first address, the working thread uses the corresponding private pointer variable to sequentially obtain the script data from the memory space;

[0042] Execute the script data, return the execution result through the working thread, add the memory barrier to the execution result, and set the private pointer variable of the working thread to a null value;

[0043] The memory barrier is a control instruction for CPU out-of-order execution, which is used to prevent out-of-order execution of multiple threads when multiple threads are executed simultaneously, thereby ensuring the global consistency of the script data.

[0044] In order to facilitate those skilled in the art to better understand this step, this step will be further explained using a virtual server as an example.

[0045] like Figure 2As shown, during the operation of the working thread, the private pointer variable corresponding to the working thread points to the first address of the memory space of the script data stored in the virtual server, and then the memory barrier is set. According to the first address, the working thread uses the corresponding private pointer variable to obtain the script data from the memory space in sequence. After the script is executed, the memory barrier is set again, and the private pointer variable of the working thread is set to a null value (NULL). Among them, the memory barrier can be an instruction to prevent the CPU from executing out of order. By setting the instruction, the instructions before the memory barrier will not fall after the memory barrier and the instructions after the memory barrier will not cross the memory barrier to execute before the memory barrier, so as to ensure the global visibility and consistency of the data. This instruction is similar to mov, including mfence, lfence and sfence.

[0046] S103, script data replacement: the configuration thread receives new script data and updates the script pointer variable.

[0047] In order to effectively perform a legality check and update on the newly received script data, in this embodiment, step S103, script data replacement: the configuration thread receives the new script data and updates the script pointer variable, specifically:

[0048] The configuration thread receives new script data, performs syntax check on the new script data, and allocates new memory space;

[0049] The new script data after syntax checking is stored in the new memory space, and the address of the new memory space is obtained;

[0050] The script pointer variable is pointed to a new memory space corresponding to the new script data, and a memory barrier is added.

[0051] In order to reduce the space occupied by the used script data, in this embodiment, step S103, script data replacement: the step of the configuration thread receiving new script data and updating the script pointer variable also includes the step of releasing the script data, which is specifically:

[0052] A memory barrier is added to the worker thread, and based on the pointer array array[bh], the configuration thread obtains and traverses the private pointer variables of all the worker threads according to the thread number of the worker thread, and releases the memory space of the script data according to the traversal result.

[0053] If the private pointer variables of all the working threads are null values ​​or point to the new memory space corresponding to the new script data, the grace period of the working thread ends, a memory barrier is added, and the memory space of the script data corresponding to the private pointer variables of the working threads is released.

[0054] In order to facilitate those skilled in the art to better understand this step, this step will be further explained by taking a virtual server as an example.

[0055] like Figure 3 As shown, after receiving new script data of WEB or CLI applications, the configuration thread first checks the legality of the script syntax, and pre-allocates memory space when the script syntax is legal, thereby avoiding applying for space when replacing script data, or failure to apply for space during replacement will cause script data replacement abnormality.

[0056] After the data preparation is completed, the script pointer variable in the virtual server is first replaced to point to the new script data, ensuring that the subsequent working threads will obtain the new script data when obtaining the script.

[0057] The configuration thread traverses all the private pointer variables of the worker threads based on the pointer array array[bh], through the address of the private pointer variable of each worker thread registered when the worker thread is started, and adds a memory barrier before the traversal, and then traverses the private pointer variables of all the worker threads. When it is determined that the private pointers of all the worker threads no longer point to the original script data, that is, when the private pointer variables of all the worker threads are NULL or point to the memory space of the new script data, the grace period ends. The memory barrier is added, and then the original script data is released and returned to applications such as WEB or CLI, thereby completing the replacement of the script data.

[0058] By applying the above technical solution, the private pointer variable of the working thread is defined according to the thread structure and the pointer structure, and the working thread and the configuration thread are initialized and configured based on the private pointer variable; the working thread is run, and the script data is obtained and executed through the private pointer variable; the configuration thread receives new script data and updates the script pointer variable; by defining the private pointer variable of the working thread, the private pointer variable of each working thread is registered in the pointer array of the configuration thread when the working thread is started, based on which the script data is obtained and executed when the working thread is running and a memory barrier is added, and the configuration thread and the memory barrier are used to update the new script data and release the memory space of the old script data, and the lock-free replacement is completed. Whether the script content is in use is determined by whether the private pointer of the working thread points to the new script content, and the old script content space is replaced and released according to the judgment result, which solves the technical problems of multi-thread competition for lock resources affecting configuration update and failure to obtain lock when the configuration thread is updated in the prior art, improves the performance and execution efficiency of the thread operation, and the operation efficiency of the script content.

[0059] At the same time, by applying the above technical solutions, when the configuration thread is preparing to configure the content, it applies for the NUMA space where the appropriate CPU core is located and cache alignment to avoid content access across NUMA, reduce cache loss, and increase performance. Compared with the inefficient thread interaction method that uses locks in multi-threading, this solution does not use locks, and only uses memory barriers to complete the replacement of script content, which increases the performance of the working thread when it is running. When the configuration thread replaces the script content, it does not use locks to block the operation of the working thread, avoiding instantaneous traffic interruption. The working thread is unaware of the script content replacement, which further increases the execution efficiency of the working thread.

[0060] Corresponding to the parallel lock-free programmable script design method in one embodiment of the present invention, the present invention also discloses a parallel lock-free programmable script design device, such as Figure 4 As shown, the device includes a thread initial configuration unit, a script data execution unit and a script data replacement unit;

[0061] in,

[0062] The thread initial configuration unit is used for thread initialization configuration: defining a private pointer variable of a working thread according to a thread structure and a pointer structure, and initializing and configuring the working thread and the configuration thread based on the private pointer variable;

[0063] The script data execution unit is used to run the thread and obtain the script data: run the working thread, obtain the script data through the private pointer variable, and execute the script data;

[0064] The script data replacement unit is used for script data replacement: the configuration thread receives new script data and updates the script pointer variable;

[0065] The thread structure includes a thread number, a thread category and a thread quantity, the thread category includes the working thread and the configuration thread, and the pointer structure includes the private pointer variable and the script pointer variable.

[0066] Optionally, in this embodiment, the script data execution unit is further used to process the script data, and the specific steps are:

[0067] The configuration thread receives the script data, performs syntax check on the script data, and allocates memory space;

[0068] storing the script data that has undergone syntax checking into the memory space;

[0069] The script pointer variable is obtained, and the script pointer variable is pointed to the memory space corresponding to the script data.

[0070] In order to reduce the space occupied by the used script data, in this embodiment, the script data replacement unit is also used to release the script data, and the specific steps are as follows:

[0071] A memory barrier is added to the worker thread, and based on the pointer array array[bh], the configuration thread obtains and traverses the private pointer variables of all the worker threads according to the thread number of the worker thread, and releases the memory space of the script data according to the traversal result.

[0072] If the private pointer variable of the working thread is a null value or points to a new memory space corresponding to the new script data, the grace period of the working thread ends, a memory barrier is added, and the memory space of the script data corresponding to the private pointer variable of the working thread is released.

[0073] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments.

[0074] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. A parallel lock-free programmable script design method, characterized in that: The method comprises: S101, thread initialization configuration: defining a private pointer variable of a working thread according to a thread structure and a pointer structure, and initializing and configuring the working thread and the configuration thread based on the private pointer variable; S102, thread running and obtaining script data: running the working thread, obtaining and executing the script data through the private pointer variable; S103, script data replacement: the configuration thread receives new script data and updates the script pointer variable; Wherein, the thread structure includes a thread number, a thread category and a thread quantity, the thread category includes the working thread and the configuration thread, and the pointer structure includes the private pointer variable and the script pointer variable; In step S101, the step of initializing and configuring the working thread and the configuration thread based on the private pointer variable includes: According to the thread structure and the pointer structure, a thread stack is constructed, and according to the thread number and the thread category, private pointer variables are defined for all working threads in the thread stack respectively, and a pointer array is created for the configuration line; Starting the working thread, and registering the addresses of the private pointer variables corresponding to all the working threads in the thread stack into the pointer array; in, Assume that the thread number is bh, and the number of working threads in the thread stack is n, then The pointer array is array[bh], bh is less than or equal to n, and n is an integer greater than 1; The step S102, thread running and obtaining script data: running the working thread, and obtaining and executing the script data through the private pointer variable includes: Running the working thread, wherein the working thread uses a private pointer variable corresponding to the working thread to point to the first address of the memory space of the script data based on the script pointer variable, and adds a memory barrier for the script data; According to the first address, the working thread uses the corresponding private pointer variable to sequentially obtain the script data from the memory space; Execute the script data, return the execution result through the working thread, add the memory barrier to the execution result, and set the private pointer variable of the working thread to a null value; The memory barrier is a control instruction for CPU out-of-order execution, which is used to prevent out-of-order execution of multiple threads when multiple threads are executed simultaneously, thereby ensuring the global consistency of the script data.

2. The method according to claim 1, characterized in that In step S102, before the thread runs and obtains the script data, a script data processing step is also included, specifically: The configuration thread receives the script data, performs syntax check on the script data, and allocates memory space; storing the script data that has undergone syntax checking into the memory space; The script pointer variable is obtained, and the script pointer variable is pointed to the memory space corresponding to the script data.

3. The method according to claim 1, characterized in that Step S103, script data replacement: the configuration thread receives new script data and updates the script pointer variable, specifically: The configuration thread receives new script data, performs syntax check on the new script data, and allocates new memory space; The new script data after syntax checking is stored in the new memory space, and the address of the new memory space is obtained; The script pointer variable is pointed to a new memory space corresponding to the new script data, and a memory barrier is added.

4. The method according to claim 3, characterized in that Step S103, script data replacement: the configuration thread receives new script data, and the step of updating the script pointer variable also includes the step of releasing the script data, which is specifically: A memory barrier is added to the worker thread, and based on the pointer array array[bh], the configuration thread obtains and traverses the private pointer variables of all the worker threads according to the thread number of the worker thread, and releases the memory space of the script data according to the traversal result. If the private pointer variables of all the working threads are null values ​​or point to the new memory space corresponding to the new script data, the grace period of the working thread ends, a memory barrier is added, and the memory space of the script data corresponding to the private pointer variables of the working threads is released.

5. A device for implementing the parallel lock-free programmable script design method according to claim 1, characterized in that: The device comprises a thread initial configuration unit, a script data execution unit and a script data replacement unit; in, The thread initial configuration unit is used for thread initialization configuration: defining a private pointer variable of a working thread according to a thread structure and a pointer structure, and initializing and configuring the working thread and the configuration thread based on the private pointer variable; The script data execution unit is used to run the thread and obtain the script data: run the working thread, obtain the script data through the private pointer variable, and execute the script data; The script data replacement unit is used for script data replacement: the configuration thread receives new script data and updates the script pointer variable; The thread structure includes a thread number, a thread category and a thread quantity, the thread category includes the working thread and the configuration thread, and the pointer structure includes the private pointer variable and the script pointer variable; The step of initializing and configuring the working thread and the configuration thread based on the private pointer variable comprises: According to the thread structure and the pointer structure, a thread stack is constructed, and according to the thread number and the thread category, private pointer variables are defined for all working threads in the thread stack respectively, and a pointer array is created for the configuration line; Starting the working thread, and registering the addresses of the private pointer variables corresponding to all the working threads in the thread stack into the pointer array; in, Assume that the thread number is bh, and the number of working threads in the thread stack is n, then The pointer array is array[bh], bh is less than or equal to n, and n is an integer greater than 1; The thread runs and obtains script data: the step of running the working thread and obtaining and executing the script data through the private pointer variable includes: Running the working thread, wherein the working thread uses a private pointer variable corresponding to the working thread to point to the first address of the memory space of the script data based on the script pointer variable, and adds a memory barrier for the script data; According to the first address, the working thread uses the corresponding private pointer variable to sequentially obtain the script data from the memory space; Execute the script data, return the execution result through the working thread, add the memory barrier to the execution result, and set the private pointer variable of the working thread to a null value; The memory barrier is a control instruction for CPU out-of-order execution, which is used to prevent out-of-order execution of multiple threads when multiple threads are executed simultaneously, thereby ensuring the global consistency of the script data.

6. The device according to claim 5, characterized in that The script data execution unit is also used to process the script data, and the specific steps are as follows: The configuration thread receives the script data, performs syntax check on the script data, and allocates memory space; storing the script data that has undergone syntax checking into the memory space; The script pointer variable is obtained, and the script pointer variable is pointed to the memory space corresponding to the script data.

7. The device according to claim 5, characterized in that The script data replacement unit is also used to release the script data, and the specific steps are as follows: A memory barrier is added to the worker thread, and based on the pointer array array[bh], the configuration thread obtains and traverses the private pointer variables of all the worker threads according to the thread number of the worker thread, and releases the memory space of the script data according to the traversal result. If the private pointer variable of the working thread is a null value or points to a new memory space corresponding to the new script data, the grace period of the working thread ends, a memory barrier is added, and the memory space of the script data corresponding to the private pointer variable of the working thread is released.

Citation Information

Patent Citations

  • Linux system network interface performance optimization method suitable for Loongson 3A

    CN112463329A

  • Data processing method and device, graphics processor and storage medium

    CN116611987A