A thread deadlock detection method and device

By obtaining the current execution instruction address and equal lock symbol of the target thread, finding the thread holding information of the mutex lock, generating a waiting relationship diagram, and detecting the ring waiting relationship, the problem of low thread deadlock detection efficiency in the existing technology is solved, and automated detection and efficient detection are realized.

CN114090322BActive Publication Date: 2025-03-14DOUYIN VISION CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111401673.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-19
Publication Date
2025-03-14
Estimated Expiration
2041-11-19

AI Technical Summary

Technical Problem

The prior art is difficult to automate detection and handling of thread deadlocks, resulting in deadlock analysis that depends on the experience and efficiency of business personnel.

Method used

By obtaining the current execution instruction address of the target thread in the waiting state, determining the iso lock symbol, finding the hold thread identification information of the mutex lock, generating a wait relationship diagram, and detecting the ring wait relationship to achieve deadlock detection.

Benefits of technology

It realizes automatic detection of thread deadlocks, improves deadlock detection efficiency, and reduces dependence on business personnel experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114090322B_ABST
    Figure CN114090322B_ABST
Patent Text Reader

Abstract

The present disclosure provides a thread deadlock detection method and device, which first obtains the address of the target instruction currently executed by multiple target threads in a waiting state; secondly, based on the address of the target instruction, determines the lock symbol of the target thread; then, based on the type of the lock symbol, finds the identification information of the holding thread of the mutex lock that matches the lock symbol; then, based on the identification information of the holding thread found, generates the waiting relationship between the target thread and other threads; finally, based on the waiting relationship, generates deadlock detection information for the target thread. The embodiment of the present disclosure determines the lock symbol of the target thread through the address of the target instruction, and then finds the identification information of the holding thread of the mutex lock according to the type of the lock symbol, thereby determining the deadlock detection information according to the found identification information, realizing automatic detection of deadlock, and improving deadlock detection efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a thread deadlock detection method and device. Background Art

[0002] When two threads access a class at the same time, some problems may arise. Concurrent thread access may cause memory leaks, uncontrollable programs, and other problems. Whether it is communication between threads or thread sharing of data, a lock mechanism is needed to control the problems caused by concurrent code. When a process accesses a class, a mutex lock for the class is generated. Only the process holding the mutex lock can access the corresponding class. When a process ends its use, the mutex lock will be passed to the next thread waiting to use the class. If a thread that does not hold the lock needs to use the class, it will enter a waiting state until it holds the mutex lock corresponding to the class.

[0003] Deadlock is a common exception in concurrent programming. Mutex locks are usually used to control the access and modification of resources by multiple threads. There are often multiple locks during program execution. In some special scenarios, threads will wait for each other to lock, forming a closed loop and causing deadlock. Deadlock usually requires professional business personnel to analyze and is difficult to handle. Summary of the invention

[0004] The embodiments of the present disclosure at least provide a thread deadlock detection method and device.

[0005] In a first aspect, an embodiment of the present disclosure provides a thread deadlock detection method, comprising:

[0006] Obtaining the addresses of target instructions currently being executed by multiple target threads in a waiting state;

[0007] Determining the lock symbol of the target thread based on the address of the target instruction;

[0008] Based on the type of the lock symbol, searching for identification information of a thread holding a mutex that matches the lock symbol;

[0009] Based on the found identification information of the holding thread, generating a waiting relationship between the target thread and other threads;

[0010] Based on the waiting relationship, deadlock detection information for the target thread is generated.

[0011] In an optional implementation manner, the address of the instruction currently executed by the target thread is obtained by the following steps:

[0012] Access the program counter register of each of the target threads to obtain the address of the instruction currently executed by each of the target threads.

[0013] In an optional implementation manner, determining the lock symbol of the target thread based on the address of the target instruction includes:

[0014] For any target thread, the address of the instruction currently executed by the target thread is symbolized, and the lock symbol is searched from the symbolized address.

[0015] In an optional implementation, searching for identification information of a thread holding a mutex that matches the mutex symbol based on the type of the mutex symbol includes:

[0016] Based on the type of the found equal lock symbol, determine the parameter storage location corresponding to the equal lock symbol;

[0017] The identification information of the thread holding the mutex lock matching the lock symbol is searched from the parameter storage location.

[0018] In an optional implementation manner, searching the parameter storage location for identification information of a thread holding a mutex that matches the lock symbol includes:

[0019] Based on the type of the lock symbol, determine the type information of the mutex lock corresponding to the lock symbol;

[0020] Based on the type information of the mutex lock corresponding to the equal lock symbol, lock structure information matching the type information of the mutex lock from the parameter storage location;

[0021] The identification information of the holding thread is parsed from the lock structure information using a parsing method that matches the lock type information.

[0022] In an optional implementation manner, generating deadlock detection information for the target thread based on the waiting relationship includes:

[0023] Based on the waiting relationship, a lock waiting relationship graph for each of the target threads is constructed; the lock waiting relationship graph includes a plurality of nodes representing the target threads, and directed connection edges representing the waiting relationship between the target threads;

[0024] Based on the lock-wait relationship graph, deadlock detection information for the target thread is generated.

[0025] In an optional implementation manner, generating deadlock detection information for the target thread based on the lock wait relationship graph includes:

[0026] In the case where a circular wait relationship exists in the lock-wait relationship graph, the deadlock detection information is generated; the deadlock detection information includes identification information of a target thread matching the circular wait relationship.

[0027] In a second aspect, an embodiment of the present disclosure further provides a thread deadlock detection device, comprising:

[0028] An acquisition module, used for acquiring addresses of target instructions currently being executed by multiple target threads in a waiting state;

[0029] A determination module, configured to determine the lock symbol of the target thread based on the address of the target instruction;

[0030] A search module, used for searching, based on the type of the lock symbol, the identification information of the thread holding the mutex lock that matches the lock symbol;

[0031] A generating module, used for generating a waiting relationship between the target thread and other threads based on the found identification information of the holding thread;

[0032] A detection module is used to generate deadlock detection information for the target thread based on the waiting relationship.

[0033] In an optional implementation manner, the acquisition module is specifically used to:

[0034] Access the program counter register of each of the target threads to obtain the address of the instruction currently executed by each of the target threads.

[0035] In an optional implementation manner, the determining module is specifically configured to:

[0036] For any target thread, the address of the instruction currently executed by the target thread is symbolized, and the lock symbol is searched from the symbolized address.

[0037] In an optional implementation manner, the search module is specifically used to:

[0038] Based on the type of the found equal lock symbol, determine the parameter storage location corresponding to the equal lock symbol;

[0039] The identification information of the thread holding the mutex lock matching the lock symbol is searched from the parameter storage location.

[0040] In an optional implementation, when the search module searches the parameter storage location for identification information of a thread holding a mutex lock that matches the lock symbol, it is configured to:

[0041] Based on the type of the lock symbol, determine the type information of the mutex lock corresponding to the lock symbol;

[0042] Based on the type information of the mutex lock corresponding to the equal lock symbol, lock structure information matching the type information of the mutex lock from the parameter storage location;

[0043] The identification information of the holding thread is parsed from the lock structure information using a parsing method that matches the lock type information.

[0044] In an optional implementation manner, the detection module is specifically used to:

[0045] Based on the waiting relationship, a lock waiting relationship graph for each of the target threads is constructed; the lock waiting relationship graph includes a plurality of nodes representing the target threads, and directed connection edges representing the waiting relationship between the target threads;

[0046] Based on the lock-wait relationship graph, deadlock detection information for the target thread is generated.

[0047] In an optional implementation manner, when the detection module generates the deadlock detection information for the target thread based on the lock wait relationship graph, it is used to:

[0048] In the case where a circular wait relationship exists in the lock-wait relationship graph, the deadlock detection information is generated; the deadlock detection information includes identification information of a target thread matching the circular wait relationship.

[0049] In a third aspect, an embodiment of the present disclosure further provides an electronic device, comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the above-mentioned first aspect, or any possible implementation of the first aspect are performed.

[0050] In a fourth aspect, an embodiment of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned first aspect or any possible implementation of the first aspect are executed.

[0051] The thread deadlock detection method and device provided by the embodiment of the present disclosure first obtain the address of the target instruction currently executed by multiple target threads in the waiting state; secondly, based on the address of the target instruction, determine the waiting lock symbol of the target thread; then, based on the type of the waiting lock symbol, find the identification information of the holding thread of the mutex lock that matches the waiting lock symbol; then, based on the identification information of the holding thread found, generate the waiting relationship between the target thread and other threads; finally, based on the waiting relationship, generate deadlock detection information for the target thread. The embodiment of the present disclosure determines the waiting lock symbol of the target thread through the address of the target instruction, and then finds the identification information of the holding thread of the mutex lock according to the type of the waiting lock symbol, thereby determining the deadlock detection information according to the found identification information, realizing automatic detection of deadlock, and improving the efficiency of deadlock detection.

[0052] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following is a brief introduction to the drawings required for use in the embodiments. The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present disclosure and are used together with the specification to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only illustrate certain embodiments of the present disclosure and should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can also be obtained based on these drawings without creative work.

[0054] Figure 1 A flowchart of a thread deadlock detection method provided by an embodiment of the present disclosure is shown;

[0055] Figure 2 A schematic diagram showing a lock waiting relationship diagram provided by an embodiment of the present disclosure is shown;

[0056] Figure 3 A schematic diagram of a thread deadlock detection device provided by an embodiment of the present disclosure is shown;

[0057] Figure 4 A schematic diagram of an electronic device provided by an embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0058] In order to make the purpose, technical scheme and advantages of the embodiments of the present disclosure clearer, the technical scheme in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.

[0059] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0060] The term "and / or" herein only describes an association relationship, indicating that three relationships may exist. For example, A and / or B may represent the following three situations: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C may represent including any one or more elements selected from the set consisting of A, B, and C.

[0061] Research has found that when a deadlock occurs, multiple threads are in a waiting state at the same time. Especially when the main thread is deadlocked, it usually causes a freeze and leads to a program crash. Deadlocks can usually be analyzed by querying the call stack and combining program code and the experience of business personnel. However, when a deadlock occurs, the amount of information in the call stack is usually very small, making it difficult to determine whether a deadlock has occurred and the waiting relationship between threads. This is heavily dependent on the knowledge and experience of business personnel and is inefficient.

[0062] Based on the above research, the present disclosure provides a thread deadlock analysis method, which determines the lock symbol of the target thread through the address of the target instruction, and then finds the identification information of the thread holding the mutex lock according to the type of the lock symbol, thereby determining the deadlock detection information based on the found identification information, realizing automatic deadlock detection, and improving deadlock detection efficiency.

[0063] To facilitate understanding of this embodiment, a thread deadlock detection method disclosed in the embodiment of the present disclosure is first introduced in detail. The execution subject of the thread deadlock detection method provided in the embodiment of the present disclosure is generally a computer device with certain computing capabilities, and the computer device includes, for example, a terminal device or a server or other processing device. In some possible implementations, the thread deadlock detection method can be implemented by a processor calling a computer-readable instruction stored in a memory.

[0064] See also Figure 1 FIG. 1 is a flowchart of a thread deadlock detection method provided by an embodiment of the present disclosure, wherein the method includes steps S101 to S105, wherein:

[0065] S101. Acquire addresses of target instructions currently being executed by multiple target threads in a waiting state.

[0066] Among them, the above-mentioned target thread can be a thread running on the iOS platform. When the current thread applies for a mutex lock of a class or object, if the lock is already held by another thread, the current thread will enter a waiting state. When the thread holding the lock releases the lock, the current thread will be awakened and try to hold the lock. When a deadlock occurs, multiple threads will wait for each other, resulting in the inability to release the held lock. If there is a main thread in the deadlocked thread, it may cause a jam and other situations.

[0067] In this step, if a thread is in a waiting state for a mutex lock, the instruction it is currently executing is the corresponding waiting lock method. Therefore, as long as the target instruction currently executed by the target thread is determined, the mutex lock it is waiting for can be determined. The target address is usually stored in the program counter register.

[0068] S102: Determine the lock symbol of the target thread based on the address of the target instruction.

[0069] In this step, after obtaining the address of the target instruction, the address of the target instruction can be symbolized to obtain the running instruction symbol, and then it is determined whether the running instruction symbol contains the waiting lock symbol, which is the symbol corresponding to the waiting lock method. If the characteristics of a segment of the running instruction symbol match the characteristics of the waiting lock symbol, the segment of the running instruction symbol is directly used as the waiting lock symbol of the target thread.

[0070] S103: Based on the type of the wait lock symbol, search for identification information of a thread holding a mutex that matches the wait lock symbol.

[0071] In this step, the identification information of the holding thread can be extracted from the parameter storage position of the mutex lock corresponding to the lock symbol. Since different mutexes have different types of lock symbols and their corresponding parameter storage positions, the parameter storage position corresponding to the lock symbol can be determined based on its type, and then the identification information of the holding thread of the mutex lock that matches the lock symbol can be found from the corresponding parameter storage position.

[0072] Since the locations of identification information of threads holding different types of mutex locks may be different, we can first determine the type information of the mutex lock corresponding to the mutex lock symbol based on the type of the mutex lock symbol, and then determine the specific location of the identification information of the holding thread in the parameter storage location based on the type information of the mutex lock, and finally find the identification information of the holding thread based on the determined specific location.

[0073] S104: Based on the found identification information of the holding thread, generate a waiting relationship between the target thread and other threads.

[0074] In this step, after finding the identification information of each holding thread, the waiting relationship between the target thread and each other thread can be obtained. For example, if the identification of a thread is 001, and the mutex lock it holds is lock a, and the identification of another thread is 002, and the mutex lock it is waiting for is lock a, then the waiting relationship between the above two threads is thread 002 waiting for thread 001.

[0075] For example, a lock waiting relationship graph for each target thread may be constructed based on the generated waiting relationship. Figure 2 As shown, it is a schematic diagram of a lock waiting relationship diagram provided by an embodiment of the present disclosure, and the diagram includes nodes representing thread 1, thread 2, thread 3 and thread 4 respectively, and directed connection edges identifying the waiting relationship between threads.

[0076] S105: Generate deadlock detection information for the target thread based on the waiting relationship.

[0077] After determining the lock waiting relationship graph, the deadlock detection information of the target thread can be generated according to the lock waiting relationship graph. Exemplarily, it can be detected whether a closed loop waiting relationship, i.e., a ring waiting relationship, is formed in the lock waiting relationship graph, such as Figure 2 As shown, thread 1, thread 2, and thread 3 form a closed-loop waiting relationship, and a deadlock is formed between the above three threads, and deadlock detection information can be generated. The deadlock detection information may include representation information of the deadlocked threads, identification information of the threads that the deadlocked threads are waiting for, information about the mutex locks held by the deadlocked threads, and information about the mutex locks that the deadlocked threads are waiting for.

[0078] The thread deadlock detection method provided by the embodiment of the present disclosure first obtains the address of the target instruction currently executed by multiple target threads in the waiting state; secondly, based on the address of the target instruction, determines the waiting symbol of the target thread; then, based on the type of the waiting symbol, searches for the identification information of the holding thread of the mutex lock that matches the waiting symbol; then, based on the identification information of the holding thread found, generates the waiting relationship between the target thread and other threads; finally, based on the waiting relationship, generates deadlock detection information for the target thread. The embodiment of the present disclosure determines the waiting symbol of the target thread through the address of the target instruction, and then searches for the identification information of the holding thread of the mutex lock according to the type of the waiting symbol, thereby determining the deadlock detection information according to the found identification information, realizing automatic detection of deadlock, and improving the efficiency of deadlock detection.

[0079] Those skilled in the art will appreciate that, in the above method of specific implementation, the order in which the steps are written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of the steps should be determined by their functions and possible internal logic.

[0080] Based on the same inventive concept, a thread deadlock detection device corresponding to the thread deadlock detection method is also provided in the embodiment of the present disclosure. Since the principle of solving the problem by the device in the embodiment of the present disclosure is similar to the above-mentioned thread deadlock detection method in the embodiment of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.

[0081] Reference Figure 3 FIG. 1 is a schematic diagram of a thread deadlock detection provided by an embodiment of the present disclosure, wherein the device includes:

[0082] An acquisition module 310 is used to acquire addresses of target instructions currently being executed by multiple target threads in a waiting state;

[0083] A determination module 320, configured to determine an equal lock symbol of the target thread based on the address of the target instruction;

[0084] A search module 330 is used to search for identification information of a thread holding a mutex that matches the mutex symbol based on the type of the mutex symbol;

[0085] A generating module 340, configured to generate a waiting relationship between the target thread and other threads based on the found identification information of the holding thread;

[0086] The detection module 350 is used to generate deadlock detection information for the target thread based on the waiting relationship.

[0087] In an optional implementation manner, the acquisition module 310 is specifically used to:

[0088] Access the program counter register of each of the target threads to obtain the address of the instruction currently executed by each of the target threads.

[0089] In an optional implementation manner, the determining module 320 is specifically configured to:

[0090] For any target thread, the address of the instruction currently executed by the target thread is symbolized, and the lock symbol is searched from the symbolized address.

[0091] In an optional implementation manner, the search module 330 is specifically used to:

[0092] Based on the type of the found equal lock symbol, determine the parameter storage location corresponding to the equal lock symbol;

[0093] The identification information of the thread holding the mutex lock matching the lock symbol is searched from the parameter storage location.

[0094] In an optional implementation, when searching the parameter storage location for identification information of a thread holding a mutex that matches the lock symbol, the search module 330 is configured to:

[0095] Based on the type of the lock symbol, determine the type information of the mutex lock corresponding to the lock symbol;

[0096] Based on the type information of the mutex lock corresponding to the equal lock symbol, lock structure information matching the type information of the mutex lock from the parameter storage location;

[0097] The identification information of the holding thread is parsed from the lock structure information using a parsing method that matches the lock type information.

[0098] In an optional implementation manner, the detection module 350 is specifically used to:

[0099] Based on the waiting relationship, a lock waiting relationship graph for each of the target threads is constructed; the lock waiting relationship graph includes a plurality of nodes representing the target threads, and directed connection edges representing the waiting relationship between the target threads;

[0100] Based on the lock-wait relationship graph, deadlock detection information for the target thread is generated.

[0101] In an optional implementation, when the detection module 350 generates the deadlock detection information for the target thread based on the lock wait relationship graph, it is configured to:

[0102] In the case where a circular wait relationship exists in the lock-wait relationship graph, the deadlock detection information is generated; the deadlock detection information includes identification information of a target thread matching the circular wait relationship.

[0103] For descriptions of the processing flow of each module in the device and the interaction flow between each module, reference may be made to the relevant descriptions in the above method embodiment, which will not be described in detail here.

[0104] Corresponds to Figure 1 The thread deadlock detection method in the present disclosure also provides an electronic device 400, such as Figure 4 FIG. 4 is a schematic diagram of the structure of an electronic device 400 provided in an embodiment of the present disclosure, including:

[0105] Processor 41, memory 42, and bus 43; memory 42 is used to store execution instructions, including internal memory 421 and external memory 422; the internal memory 421 is also called internal memory, which is used to temporarily store the operation data in the processor 41 and the data exchanged with the external memory 422 such as a hard disk. The processor 41 exchanges data with the external memory 422 through the internal memory 421. When the electronic device 400 is running, the processor 41 communicates with the memory 42 through the bus 43, so that the processor 41 executes the following instructions:

[0106] Obtaining the addresses of target instructions currently being executed by multiple target threads in a waiting state;

[0107] Determining the lock symbol of the target thread based on the address of the target instruction;

[0108] Based on the type of the lock symbol, searching for identification information of a thread holding a mutex that matches the lock symbol;

[0109] Based on the found identification information of the holding thread, generating a waiting relationship between the target thread and other threads;

[0110] Based on the waiting relationship, deadlock detection information for the target thread is generated.

[0111] In an optional implementation manner, obtaining the address of the instruction currently executed by the target thread in the instruction executed by the processor 41 includes:

[0112] Access the program counter register of each of the target threads to obtain the address of the instruction currently executed by each of the target threads.

[0113] In an optional implementation, in the instruction executed by the processor 41, determining the lock symbol of the target thread based on the address of the target instruction includes:

[0114] For any target thread, the address of the instruction currently executed by the target thread is symbolized, and the lock symbol is searched from the symbolized address.

[0115] In an optional implementation manner, in the instruction executed by the processor 41, searching for identification information of a thread holding a mutex lock matching the mutex symbol based on the type of the mutex symbol includes:

[0116] Based on the type of the found equal lock symbol, determine the parameter storage location corresponding to the equal lock symbol;

[0117] The identification information of the thread holding the mutex lock matching the lock symbol is searched from the parameter storage location.

[0118] In an optional implementation manner, in the instruction executed by the processor 41, searching the parameter storage location for identification information of a thread holding a mutex that matches the lock symbol includes:

[0119] Based on the type of the lock symbol, determine the type information of the mutex lock corresponding to the lock symbol;

[0120] Based on the type information of the mutex lock corresponding to the equal lock symbol, lock structure information matching the type information of the mutex lock from the parameter storage location;

[0121] The identification information of the holding thread is parsed from the lock structure information using a parsing method that matches the lock type information.

[0122] In an optional implementation manner, in the instruction executed by the processor 41, generating the deadlock detection information for the target thread based on the waiting relationship includes:

[0123] Based on the waiting relationship, a lock waiting relationship graph for each of the target threads is constructed; the lock waiting relationship graph includes a plurality of nodes representing the target threads, and directed connection edges representing the waiting relationship between the target threads;

[0124] Based on the lock-wait relationship graph, deadlock detection information for the target thread is generated.

[0125] In an optional implementation manner, in the instruction executed by the processor 41, generating the deadlock detection information for the target thread based on the lock wait relationship graph includes:

[0126] In the case where a circular wait relationship exists in the lock-wait relationship graph, the deadlock detection information is generated; the deadlock detection information includes identification information of a target thread matching the circular wait relationship.

[0127] The present disclosure also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the thread deadlock detection method described in the above method embodiment are executed. The storage medium can be a volatile or non-volatile computer-readable storage medium.

[0128] The embodiments of the present disclosure also provide a computer program product, which carries a program code. The instructions included in the program code can be used to execute the steps of the thread deadlock detection method described in the above method embodiment. For details, please refer to the above method embodiment, which will not be repeated here.

[0129] The computer program product may be implemented in hardware, software or a combination thereof. In one optional embodiment, the computer program product is implemented as a computer storage medium. In another optional embodiment, the computer program product is implemented as a software product, such as a software development kit (SDK).

[0130] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. In the several embodiments provided in the present disclosure, it should be understood that the disclosed system, device and method can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the device or unit can be electrical, mechanical or other forms.

[0131] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0132] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0133] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present disclosure, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0134] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present disclosure, which are used to illustrate the technical solutions of the present disclosure, rather than to limit them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed in the present disclosure, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.

Claims

1. A thread deadlock detection method, characterized in that: include: Obtaining the addresses of target instructions currently being executed by multiple target threads in a waiting state; Determining the lock symbol of the target thread based on the address of the target instruction; Based on the type of the wait lock symbol, searching for identification information of a thread holding a mutex that matches the wait lock symbol; Based on the found identification information of the holding thread, generating a waiting relationship between the target thread and other threads; Based on the waiting relationship, generating deadlock detection information for the target thread, Wherein, determining the lock symbol of the target thread based on the address of the target instruction includes: For any target thread, the address of the instruction currently executed by the target thread is symbolized, and the lock symbol is searched from the symbolized address.

2. The method according to claim 1, characterized in that The address of the instruction currently executed by the target thread is obtained by following the steps below: Access the program counter register of each of the target threads to obtain the address of the instruction currently executed by each of the target threads.

3. The method according to claim 1, characterized in that The searching, based on the type of the lock symbol, for identification information of a thread holding a mutex that matches the lock symbol includes: Based on the type of the found equal lock symbol, determine the parameter storage location corresponding to the equal lock symbol; The identification information of the thread holding the mutex lock matching the lock symbol is searched from the parameter storage location.

4. The method according to claim 3, characterized in that The step of searching the parameter storage location for identification information of a thread holding a mutex that matches the mutex symbol includes: Based on the type of the lock symbol, determine the type information of the mutex lock corresponding to the lock symbol; Based on the type information of the mutex lock corresponding to the equal lock symbol, lock structure information matching the type information of the mutex lock from the parameter storage location; The identification information of the holding thread is parsed from the lock structure information using a parsing method that matches the lock type information.

5. The method according to claim 1, characterized in that The generating of deadlock detection information for the target thread based on the waiting relationship includes: Based on the waiting relationship, a lock waiting relationship graph for each of the target threads is constructed; the lock waiting relationship graph includes a plurality of nodes representing the target threads, and directed connection edges representing the waiting relationship between the target threads; Based on the lock-wait relationship graph, deadlock detection information for the target thread is generated.

6. The method according to claim 5, characterized in that The generating of deadlock detection information for the target thread based on the lock-wait relationship graph includes: In the case where a circular wait relationship exists in the lock-wait relationship graph, the deadlock detection information is generated; the deadlock detection information includes identification information of a target thread matching the circular wait relationship.

7. A thread deadlock detection device, characterized in that: include: An acquisition module, used for acquiring addresses of target instructions currently being executed by multiple target threads in a waiting state; A determination module, configured to determine the lock symbol of the target thread based on the address of the target instruction; A search module, used for searching, based on the type of the lock symbol, the identification information of the thread holding the mutex lock that matches the lock symbol; A generating module, used for generating a waiting relationship between the target thread and other threads based on the found identification information of the holding thread; A detection module, configured to generate deadlock detection information for the target thread based on the waiting relationship, Wherein, the determination module is further configured as: For any target thread, the address of the instruction currently executed by the target thread is symbolized, and the lock symbol is searched from the symbolized address.

8. An electronic device, characterized in that: include: A processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the steps of the thread deadlock detection method as described in any one of claims 1 to 6 are performed.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the thread deadlock detection method according to any one of claims 1 to 6 are executed.

Citation Information

Patent Citations

  • Method for implementing spin lock in database

    CN102129391A

  • System restarting reason detection method, device and terminal equipment

    CN103942113A