A thread running method, device, computer equipment and storage medium

By establishing a target mapping table to record the relationship between waiting threads and locks, the problem of being unable to determine the holder when a thread is waiting for a lock is solved, and the effect of reducing waiting time is achieved.

CN113742091BActive Publication Date: 2024-09-17SHENZHEN TCL NEW-TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111012205.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-08-31
Publication Date
2024-09-17
Estimated Expiration
2041-08-31

AI Technical Summary

Technical Problem

When running multiple threads in parallel, it is impossible to determine the holders of other locks that the thread holding the lock is waiting for while the thread is waiting for the lock. As a result, threads holding other locks cannot be prioritized and the waiting time cannot be reduced.

Method used

Establish a target mapping table to record the correspondence between waiting threads, locks and holding threads. Use this table to determine the holding thread of the lock that the waiting thread needs to wait for and the lock it is waiting for, and run the holding thread after the release to reduce Waiting time.

Benefits of technology

Through the target mapping table to determine the holding thread and the lock it is waiting for, you can run the holding thread first and then run the waiting thread after the release, thereby reducing the time for the waiting thread to acquire the lock.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113742091B
    Figure CN113742091B
Patent Text Reader

Abstract

The embodiments of the present application disclose a thread running method, apparatus, computer equipment and storage medium. Since the established target mapping table includes the corresponding relationship between waiting threads, locks and holding threads. Therefore, when it is detected that the first waiting thread needs to wait for the first target lock, the first holding thread holding the first target lock and the second target lock that the first holding thread is waiting for can be determined based on the target mapping table. And the second holding thread holding the second target lock is searched from the target mapping table. Then the second holding thread is run first, and after the second target lock is released, the first holding thread is run. Since the second holding thread can be run first and the first holding thread can be run after the second target lock is released. Therefore, the first waiting thread can obtain the first target lock faster, so that the time for the first waiting thread to wait for the first target lock can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computers, and in particular to a thread running method, device, computer equipment and storage medium. Background Art

[0002] With the development of science and technology, people have higher and higher requirements for computer operation efficiency. In order to improve the operation efficiency of computers, multiple threads are generally run in parallel. When multiple threads are run in parallel, there will be a phenomenon that multiple threads access the same resource at the same time. When multiple threads access the same resource at the same time, errors will occur during access due to the lack of synchronization of resources.

[0003] In order to solve this technical problem, a lock mechanism is introduced, that is, the thread can only execute after acquiring the lock corresponding to the resource. However, in the process of acquiring the lock, if the lock is already held by another thread, the thread needs to wait until the holding thread completes its operation and releases the lock before it can acquire the lock.

[0004] Currently, in the process of waiting for a lock, the thread can determine the lock holding thread, so that the lock holding thread can be run first, thereby reducing the waiting time. However, if the lock holding thread is also waiting for other locks, the thread cannot obtain the lock holding threads of other locks, and thus cannot run the lock holding threads of other locks first, thereby reducing the waiting time of the thread. Summary of the invention

[0005] The embodiments of the present application provide a thread running method, apparatus, computer device and storage medium, which can solve the current problem that the waiting time of threads cannot be reduced.

[0006] The present application embodiment provides a thread running method, including:

[0007] Establishing a target mapping table, the target mapping table includes the correspondence between waiting threads, locks, and holding threads;

[0008] When it is detected that the first waiting thread needs to wait for the first target lock, based on the target mapping table, a first holding thread corresponding to the first target lock and a second target lock that the first holding thread waits for are determined;

[0009] Searching the target mapping table for a second holding thread corresponding to the second target lock;

[0010] The second holding thread is run, and after the second target lock is released, the first holding thread is run.

[0011] Based on one aspect provided by the present application, a thread running device is also provided, including:

[0012] An establishment module is used to establish a target mapping table, wherein the target mapping table includes a correspondence between waiting threads, locks, and holding threads;

[0013] A determination module, configured to determine, when it is detected that the first waiting thread needs to wait for the first target lock, based on the target mapping table, a first holding thread corresponding to the first target lock and a second target lock that the first holding thread is waiting for;

[0014] A search module, used for searching the target mapping table for a second holding thread corresponding to the second target lock;

[0015] The running module is used to run the second holding thread and, after releasing the second target lock, run the first holding thread.

[0016] According to one aspect of the present application, a storage medium is further provided, on which a computer program is stored, wherein the computer program implements the steps of the above method when executed by a processor.

[0017] According to one aspect provided by the present application, a computer device is also provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.

[0018] In the embodiment of the present application, since the established target mapping table includes the correspondence between the waiting thread, the lock, and the holding thread. Therefore, when it is detected that the first waiting thread needs to wait for the first target lock, the first holding thread corresponding to the first target lock and the second target lock that the first holding thread is waiting for can be determined based on the target mapping table. And the second holding thread corresponding to the second target lock is searched from the target mapping table. That is, in the present embodiment, the second holding thread can be determined by the target mapping table.

[0019] Because the second holding thread can be determined, the second holding thread can be run first, and after the second target lock is released, the first holding thread can be run. Because the second holding thread can be run first, and after the second target lock is released, the first holding thread can be run. Therefore, the first waiting thread can quickly acquire the first target lock, so that the time the first waiting thread waits for the first target lock can be reduced. 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 invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0021] Figure 1 It is a flowchart of a thread running method provided in an embodiment of the present application;

[0022] Figure 2 is a schematic diagram of the structure of a thread running device provided in an embodiment of the present application;

[0023] Figure 3 It is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0024] 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 invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0025] The thread running method provided in the embodiment of the present application can be applied to a computer device, which may be a mobile phone, a tablet computer, a laptop computer, a desktop computer, a wearable device, etc. The present application does not specifically limit the specific type of the computer device.

[0026] In order to illustrate the technical solution of the present application, the following is described through specific embodiments. It should be noted that the description order of the following embodiments is not intended to limit the preferred order of the embodiments.

[0027] At present, in the process of running multiple threads in parallel, in order to prevent access errors, threads can only be executed after acquiring the corresponding locks. However, if a thread is waiting for a lock and the thread holding the lock is also waiting for other locks, the thread cannot acquire the threads holding other locks, and thus cannot run the threads holding other locks first, and thus cannot reduce the waiting time of the thread.

[0028] For example, when a computer device starts application A, it needs to access resource 1; when it starts application B, it needs to access resource 1 and resource 2; when it starts application C, it needs to access resource 2. The lock corresponding to resource 1 is lock a, and the lock corresponding to resource 2 is lock b. The process of starting application A corresponds to thread 1, the process of starting application B corresponds to thread 2, and the process of starting application C corresponds to thread 3.

[0029] When the computer device needs to start application A, that is, when it needs to run thread 1, lock a is held by thread 2, and at this time thread 2 is waiting for lock b, and lock b is held by thread 3. Then thread 1 needs to wait until thread 2 and thread 3 finish running before it can obtain lock a.

[0030] However, currently thread 1 can only determine thread 2, the holder of lock a, but cannot determine lock b that thread 1 is waiting for and thread 3, the holder of lock b. Since lock b and thread 3, the holder of lock b, cannot be determined, thread 3 cannot be run first, and thus the time thread 1 waits for lock a cannot be reduced.

[0031] In order to solve this technical problem, an embodiment of the present application provides a thread running method, in which the established target mapping table includes the corresponding relationship between waiting threads, locks and holding threads. Therefore, when it is detected that the first waiting thread (the first waiting thread here can be the above-mentioned thread 1) needs to wait for the first target lock (the second target lock here can be the above-mentioned lock a), the first holding thread corresponding to the first target lock (the first holding thread here can be the above-mentioned thread 2) and the second target lock that the first holding thread is waiting for (the second target lock here can be the above-mentioned lock b) can be determined based on the target mapping table. And the second holding thread corresponding to the second target lock (the second holding thread here can be the above-mentioned thread 3) is searched from the target mapping table.

[0032] That is, in this embodiment, the second holding thread can be determined by the target mapping table. Because the second holding thread can be determined, the second holding thread can be run first, and after the second target lock is released, the first holding thread can be run. Since the second holding thread can be run first, and after the second target lock is released, the first holding thread can be run. Therefore, the first waiting thread can quickly acquire the first target lock, so that the time for the first waiting thread to wait for the first target lock can be reduced.

[0033] It should be understood that the above is only an example of the present application. In practical applications, the technical solution of the present application can be applied to scenarios where multiple threads are run in parallel.

[0034] Refer to the following Figure 1 , a thread running method provided in an embodiment of the present application is described in detail, the method can be executed by a processor of a computer device, the method comprising:

[0035] Step S101: Establish a target mapping table, which includes the correspondence between waiting threads, locks, and holding threads.

[0036] Among them, a lock is a kind of permission. A thread can access the resource corresponding to the lock only after acquiring the lock. The user can set the type of lock according to the actual situation. For example, the lock in the embodiment of the present application can be a read-write lock, a mutex lock, a conditional lock, and a spin lock. This application does not make specific restrictions here.

[0037] It should be noted that when the lock is a read-write lock, the target mapping table can be a linked list. Because when the read-write lock is a read lock, at least two or more threads can read the lock at the same time. Therefore, when the lock is a read-write lock, the target mapping table can be a linked list. A linked list refers to a non-continuous and non-sequential storage structure on a physical storage unit.

[0038] The above resource may be a code, or may also be the occupancy rate of a central processing unit (CPU). The user may set the specific type of resource according to actual conditions, and this application does not limit it here.

[0039] The waiting thread is the thread that is waiting for the lock. The holding thread is the thread that currently holds the lock. It should be noted that the waiting thread can also be the holding thread at the same time, and the holding thread can also be the waiting thread at the same time.

[0040] For example, waiting thread 1 is waiting for lock a, but since waiting thread 1 can also hold lock b at the same time, at this time, the waiting thread 1 is also a holding thread. Holding thread 1 holds lock a, but can also wait for lock c at the same time, then the holding thread 1 can also be a waiting thread.

[0041] The process of establishing a target mapping table can be as follows: when the computer device detects that a thread is waiting for a lock, that is, when it detects that there is a waiting thread, the waiting thread and the lock that the waiting thread is waiting for are associated and stored in the target mapping table; when it is detected that a thread holds a lock, that is, when it detects that there is a holding thread, the holding thread and the lock held by the holding thread are associated and stored in the target mapping table.

[0042] That is, in this embodiment, the correspondence between the waiting thread, the lock, and the holding thread is stored in the target mapping table, so that the holding thread of the lock that the waiting thread is waiting for can be determined through the target mapping table.

[0043] For example, when the computer device detects that holding thread 1 holds lock 1, the holding thread 1 and lock 1 are associated and stored in the target mapping table. When it is detected that waiting thread 1 holds lock 2, the waiting thread 1 and lock 2 are associated and stored in the target mapping table. When it is detected that waiting thread 1 is waiting for lock 1, the waiting thread 1 and lock 1 are associated and stored in the target mapping table.

[0044] Then, when the computer device detects that waiting thread 2 is waiting for lock 2, the target mapping table can be used to determine that the holder of lock 2 is waiting for thread 1 and the lock 1 that waiting thread 1 is waiting for, and the target mapping table can be used to determine that the holder of lock 1 is holding thread 1.

[0045] The user can set the way in which waiting threads, locks, and holding threads are stored in the target mapping table according to actual conditions. For example, in an embodiment of the present application, waiting threads, locks, and holding threads are stored in the target mapping table in the form of structures. This embodiment of the present application is not limited here.

[0046] A structure is a new data type composed of a group of data. The types of the data can be different but they are related. For example, a structure consists of a student ID string, a name string, and an age integer variable. The above integer variable is a type of data.

[0047] Step S102: When it is detected that the first waiting thread needs to wait for the first target lock, a first holding thread corresponding to the first target lock and a second target lock that the first holding thread is waiting for are determined based on the target mapping table.

[0048] Since the target mapping table includes the correspondence between waiting threads, locks and holding threads, when the computer device detects that the first waiting thread needs to wait for the first target lock, it can determine the first holding thread holding the first target lock and the second target lock that the first holding thread is waiting for through the target mapping table.

[0049] It should be understood that when the computer device detects that the first waiting thread needs to wait for the first target lock, it also needs to associate the first waiting thread with the first target lock and store it in the target mapping table so that the first target lock that the first waiting thread is waiting for can be found in the target mapping table.

[0050] Step S103: searching the target mapping table for a second holding thread corresponding to the second target lock.

[0051] Since the target mapping table includes the correspondence between waiting threads, locks, and holding threads, when the computer device detects that the first waiting thread needs to wait for the first target lock, it can not only determine the first holding thread holding the first target lock and the second target lock that the first holding thread is waiting for through the target mapping table, but also find the second holding thread holding the second target lock through the target mapping table.

[0052] It should be noted that the computer device stops searching when the found holding thread is not a waiting thread. Therefore, the second holding thread here is not a waiting thread. Therefore, searching the target mapping table for the second holding thread corresponding to the second target lock includes:

[0053] Search the target mapping table for a candidate holding thread corresponding to the second target lock; if the candidate holding thread is a waiting thread, continue searching the target mapping table until the candidate holding thread found is not a waiting thread, and then use the candidate holding thread as the second holding thread.

[0054] Step S104: Run the second holding thread, and after releasing the second target lock, run the first holding thread.

[0055] Because the computer device can find the first holding thread and the second holding thread from the target mapping table, the computer device can directly run the second holding thread first, and after the second holding thread is completed and releases the second target lock, run the first holding thread, and release the first target lock after the first holding thread is completed.

[0056] Since the second holding thread and the first holding thread can be run first, the first waiting thread can acquire the first target lock as quickly as possible, thereby reducing the time the first waiting thread waits for the first target lock.

[0057] In some possible implementations, there are some common threads whose priority cannot be lowered. Therefore, the detailed process of running the second holding thread and then running the first holding thread after releasing the second target lock may be:

[0058] First, an original priority table is obtained. The original priority table includes the priorities of the holding thread and ordinary threads. The ordinary thread is a thread whose priority in the original priority table is higher than that of the holding thread.

[0059] Then, the common threads satisfying the preset degradation condition in the original priority table are determined, and the priorities of the first holding thread and the second holding thread are set higher than the priorities of the common threads satisfying the degradation condition, so as to obtain an updated priority table.

[0060] Finally, the second holding thread is run according to the updated priority table, and after the second target lock is released, the first holding thread is run.

[0061] It should be understood that when the candidate holding thread corresponding to the second target lock found in the target mapping table is a waiting thread, the candidate holding threads are run in sequence after the second holding thread releases the lock, and the first holding thread is run after the candidate holding thread holding the second target lock is run.

[0062] After the first holding thread is run and the first target lock is released, the first waiting thread can obtain the first target lock. After the first waiting thread obtains the first target lock, the first waiting thread is used as a new first holding thread, and the new first holding thread and the first target lock are associated and stored in the target mapping table.

[0063] As can be seen from the above, in the embodiment of the present application, since the established target mapping table includes the correspondence between the waiting thread, the lock, and the holding thread. Therefore, when it is detected that the first waiting thread needs to wait for the first target lock, the first holding thread corresponding to the first target lock and the second target lock that the first holding thread is waiting for can be determined based on the target mapping table. And the second holding thread corresponding to the second target lock is searched from the target mapping table. That is, in this embodiment, the second holding thread can be determined by the target mapping table.

[0064] Because the second holding thread can be determined, the second holding thread can be run first, and after the second target lock is released, the first holding thread can be run. Because the second holding thread can be run first, and after the second target lock is released, the first holding thread can be run. Therefore, the first waiting thread can quickly acquire the first target lock, so that the time the first waiting thread waits for the first target lock can be reduced.

[0065] It should be understood that the serial numbers of the steps in the above embodiments do not imply the order of execution, and the order of execution of the steps is determined by their functions and internal logic.

[0066] In order to better implement the above method, accordingly, an embodiment of the present invention further provides a thread running device, and the thread running device is specifically integrated in a computer device.

[0067] Reference Figure 2 , the thread running device includes:

[0068] The establishing module 201 is used to establish a target mapping table, which includes the correspondence between waiting threads, locks, and holding threads.

[0069] The determination module 202 is used to determine, based on the target mapping table, a first holding thread corresponding to the first target lock and a second target lock that the first holding thread is waiting for when it is detected that the first waiting thread needs to wait for the first target lock.

[0070] The search module 203 is used to search the target mapping table for the second holding thread corresponding to the second target lock.

[0071] The running module 204 is used to run the second holding thread, and after releasing the second target lock, run the first holding thread.

[0072] Optionally, the thread running device further includes:

[0073] The first storage module is used to associate and store the first waiting thread and the first target lock in the target mapping table when it is detected that the first waiting thread needs to wait for the first target lock.

[0074] Optionally, the thread running device further includes:

[0075] The second storage module is used for, when the first waiting thread acquires the first target lock, using the first waiting thread as a new first holding thread, and associating the new first holding thread with the first target lock and storing them in the target mapping table.

[0076] Optionally, the waiting threads, locks, and holding threads are stored in the target mapping table in the form of structures.

[0077] Optionally, when the lock includes a read-write lock, the target mapping table is a linked list.

[0078] Optionally, the search module 203 is specifically configured to execute:

[0079] Searching the target mapping table for a candidate holding thread corresponding to the second target lock;

[0080] If the candidate holding thread is a waiting thread, the search continues from the target mapping table until the candidate holding thread found is not a waiting thread, and the candidate holding thread is used as the second holding thread.

[0081] Optionally, the operation module 204 is specifically used to execute:

[0082] Obtain an original priority table, the original priority table includes the priorities of the holding thread and common threads, the common thread being a thread having a higher priority than the holding thread in the original priority table;

[0083] Determine the common threads that meet the preset downgrade condition in the original priority table, and set the priority of the first holding thread and the second holding thread to be higher than the priority of the common threads that meet the downgrade condition, to obtain an updated priority table;

[0084] The second holding thread is run according to the updated priority table, and after the second target lock is released, the first holding thread is run.

[0085] In the thread running device of the present embodiment, since the target mapping table established by the establishment module 201 includes the correspondence between the waiting thread, the lock, and the holding thread. Therefore, when the determination module 202 detects that the first waiting thread needs to wait for the first target lock, it can determine the first holding thread corresponding to the first target lock and the second target lock that the first holding thread is waiting for based on the target mapping table. The search module 203 can search the second holding thread corresponding to the second target lock from the target mapping table. That is, in the present embodiment, the second holding thread can be determined by the target mapping table.

[0086] Because the second holding thread can be determined. Therefore, the running module 204 can run the second holding thread first, and after releasing the second target lock, run the first holding thread. Since the second holding thread can be run first and after releasing the second target lock, the first holding thread can be run. Therefore, the first waiting thread can quickly acquire the first target lock, so that the time for the first waiting thread to wait for the first target lock can be reduced.

[0087] It should be noted that, since the information interaction, execution process and other contents in the above-mentioned device are based on the same concept as the method embodiment, the specific execution process can refer to the method embodiment, and this application will not repeat them here.

[0088] In addition, the present application also provides a computer device, such as Figure 3 As shown, it shows a schematic diagram of the structure of the computer device involved in the embodiment of the present application, specifically:

[0089] The computer device may include one or more processing core processors 301, one or more computer readable storage media memories 302, a power supply 303, an input unit 304 and other components. Those skilled in the art will appreciate that Figure 3 The computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. Among them:

[0090] The processor 301 is the control center of the computer device. It uses various interfaces and lines to connect various parts of the entire computer device. By running or executing software programs and / or modules stored in the memory 302 and calling data stored in the memory 302, it executes various functions of the computer device and processes data, thereby monitoring the computer device as a whole. Optionally, the processor 301 may include one or more processing cores; preferably, the processor 301 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 301.

[0091] The memory 302 can be used to store software programs and modules. The processor 301 executes various functional applications and data processing by running the software programs and modules stored in the memory 302. The memory 302 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 302 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 302 may also include a memory controller to provide the processor 301 with access to the memory 302.

[0092] The computer device also includes a power supply 303 for supplying power to various components. Preferably, the power supply 303 can be logically connected to the processor 301 through a power management system, so as to manage charging, discharging, and power consumption through the power management system. The power supply 303 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.

[0093] The computer device may further include an input unit 304, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.

[0094] Although not shown, the computer device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 301 in the computer device will load the executable files corresponding to the processes of one or more application programs into the memory 302 according to the following instructions, and the processor 301 will run the application programs stored in the memory 302, thereby realizing various functions, such as:

[0095] Establish a target mapping table, which includes the correspondence between waiting threads, locks, and holding threads;

[0096] When it is detected that the first waiting thread needs to wait for the first target lock, based on the target mapping table, determining the first holding thread corresponding to the first target lock and the second target lock that the first holding thread is waiting for;

[0097] Searching the target mapping table for a second holding thread corresponding to the second target lock;

[0098] The second holding thread is run, and after the second target lock is released, the first holding thread is run.

[0099] According to one aspect of the present application, a computer program product or a computer program is also provided, the computer program product or the computer program includes a computer instruction, and the computer instruction is stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the method provided in various optional implementations in the above embodiments.

[0100] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.

[0101] To this end, an embodiment of the present application provides a storage medium in which a plurality of instructions are stored, and the instructions can be loaded by a processor to execute the steps in any thread running method provided in the embodiment of the present application. For example, the instructions can execute the following steps:

[0102] Establish a target mapping table, which includes the correspondence between waiting threads, locks, and holding threads;

[0103] When it is detected that the first waiting thread needs to wait for the first target lock, based on the target mapping table, determining the first holding thread corresponding to the first target lock and the second target lock that the first holding thread is waiting for;

[0104] Searching the target mapping table for a second holding thread corresponding to the second target lock;

[0105] The second holding thread is run, and after the second target lock is released, the first holding thread is run.

[0106] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.

[0107] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0108] Since the instructions stored in the storage medium can execute the steps in any thread running method provided in the embodiments of the present application, the beneficial effects that can be achieved by any thread running method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.

[0109] The above is a detailed introduction to a thread running method, device, computer equipment and storage medium provided in an embodiment of the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A thread running method, It is characterized in that include: Establishing a target mapping table, wherein the target mapping table includes a correspondence between waiting threads, locks, and holding threads; When it is detected that the first waiting thread needs to wait for the first target lock, determining, based on the target mapping table, a first holding thread corresponding to the first target lock and a second target lock that the first holding thread is waiting for; Searching the target mapping table for a second holding thread corresponding to the second target lock; Running the second holding thread, and after releasing the second target lock, running the first holding thread; The searching the target mapping table for a second holding thread corresponding to the second target lock includes: Searching the target mapping table for a candidate holding thread corresponding to the second target lock; If the candidate holding thread is a waiting thread, continue searching from the target mapping table until the candidate holding thread found is not a waiting thread, and then use the candidate holding thread as the second holding thread.

2. The thread running method according to claim 1, It is characterized in that When it is detected that the first waiting thread needs to wait for the first target lock, the method further includes: The first waiting thread and the first target lock are associated and stored in the target mapping table.

3. The thread running method according to claim 1, It is characterized in that After running the second holding thread and releasing the second target lock, and then running the first holding thread, the method further includes: When the first waiting thread acquires the first target lock, the first waiting thread is used as a new first holding thread, and the new first holding thread and the first target lock are associated and stored in the target mapping table.

4. The thread running method according to claim 1, It is characterized in that The waiting thread, the lock, and the holding thread are stored in the target mapping table in the form of a structure.

5. The thread running method according to claim 1, It is characterized in that When the lock includes a read-write lock, the target mapping table is a linked list.

6. The thread running method according to any one of claims 1 to 5, It is characterized in that The step of running the second holding thread and, after releasing the second target lock, running the first holding thread comprises: Obtaining an original priority table, wherein the original priority table includes the priorities of the holding thread and common threads, wherein the common thread is a thread having a higher priority than the holding thread in the original priority table; Determine a common thread that meets a preset downgrade condition in the original priority table, and set the priority of the first holding thread and the second holding thread to be higher than the priority of the common thread that meets the downgrade condition, to obtain an updated priority table; The second holding thread is run according to the updated priority table, and the first holding thread is run after the second target lock is released.

7. A thread running device, It is characterized in that include: An establishing module, used for establishing a target mapping table, wherein the target mapping table includes a correspondence between waiting threads, locks, and holding threads; A determination module, configured to determine, when detecting that a first waiting thread needs to wait for a first target lock, a first holding thread corresponding to the first target lock and a second target lock that the first holding thread is waiting for based on the target mapping table; A search module, used for searching the target mapping table for a second holding thread corresponding to the second target lock; A running module, used for running the second holding thread, and after releasing the second target lock, running the first holding thread; The search module is specifically used to perform: Searching the target mapping table for a candidate holding thread corresponding to the second target lock; If the candidate holding thread is a waiting thread, continue searching from the target mapping table until the candidate holding thread found is not a waiting thread, and then use the candidate holding thread as the second holding thread.

8. A computer device, It is characterized in that It comprises a memory and a processor; the memory stores an application program, and the processor is used to run the application program in the memory to execute the steps in the thread running method according to any one of claims 1 to 6.

9. A storage medium, It is characterized in that The storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor to execute the steps in the thread running method according to any one of claims 1 to 6.