A method and device for detecting thread exception blocking and an electronic device

CN123011544APending Publication Date: 2026-10-30HANGZHOU EZVIZ SOFTWARE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510518362.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-23
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

当线程异常阻塞时,将会导致系统的响应时间变长,阻碍系统运行

Benefits of technology

[0037]本申请实施例提供的线程异常阻塞的检测方法、装置及电子设备,应用于嵌入式系统,先获取当前状态为阻塞态的待检测线程的第一阻塞点;对第一阻塞点与预设的待检测线程的正常阻塞点进行匹配;在第一阻塞点与正常阻塞点匹配失败的情况下,判定待检测线程的当前状态为异常阻塞状态。预先获取线程正常运行会发生正常阻塞的固定阻塞点,当线程进入阻塞态时,对比当前阻塞位置与固定阻塞位置,若不一致,即可判定线程当前的阻塞态为异常阻塞,无需对线程所调用的资源进行复杂计算,降低了线程异常阻塞检测的复杂程度和计算难度,应用于底层系统层,相比于在应用层埋点计算接口调用时间的计算方式,更适配于算力及内存资源有限的嵌入式系统,即使是算力资源丰富的其他系统,也可以通过本申请实施例提供的方法,实现更简单地检测线程的异常阻塞。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123011544A_ABST
    Figure CN123011544A_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a thread abnormal blocking detection method and device and electronic equipment, and relate to the technical field of embedded systems. The method is applied to an embedded system and includes the following steps: obtaining a first blocking point of a to-be-detected thread in a blocking state; matching the first blocking point with a preset normal blocking point of the to-be-detected thread; and determining that the current state of the to-be-detected thread is an abnormal blocking state if the first blocking point and the normal blocking point fail to match. The embodiments of the present application achieve more suitable detection of thread abnormal blocking in an embedded system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of embedded system technology, and in particular to a method, apparatus and electronic device for detecting abnormal thread blocking. Background Technology

[0002] A thread is the smallest unit of computation that an operating system can schedule. Thread states include the initial state, blocked state, ready state (waiting to be scheduled), and running state. The blocked state refers to a thread's state where execution is suspended because it is waiting for certain specific events to occur, such as waiting for I / O (input / output) operations to complete, waiting to acquire a lock, or waiting for a specific condition variable. When a thread is abnormally blocked, it will increase the system's response time and hinder system operation.

[0003] In related technologies, processing is typically performed at the application layer, such as in cloud services and database services. This involves embedding tracking points at the application's upper-layer interfaces and determining anomalies based on the computational interface call time. Such calculations are complex and resource-intensive. In embedded systems, due to limited computing resources, it is difficult to detect thread blocking anomalies in this way. A more suitable method for detecting thread blocking anomalies in embedded systems is needed. Summary of the Invention

[0004] The purpose of this application is to provide a method, apparatus, and electronic device for detecting thread abnormal blocking, so as to achieve thread abnormal blocking detection that is more suitable for embedded systems. The specific technical solution is as follows:

[0005] In a first aspect, embodiments of this application provide a method for detecting thread abnormal blocking, applied to an embedded system, comprising:

[0006] Find the first blocking point of the thread to be detected that is currently in a blocked state;

[0007] The first blocking point is matched with the preset normal blocking point of the thread to be detected;

[0008] If the first blocking point fails to match the normal blocking point, the current state of the thread to be detected is determined to be an abnormal blocking state.

[0009] In one embodiment of this application, after determining that the current state of the thread to be detected is abnormally blocked, the method further includes:

[0010] The abnormal duration during which the state of the thread to be detected is abnormally blocked;

[0011] If the duration of the abnormality exceeds a preset time threshold, the state of the thread to be detected is determined to be a potential deadlock state.

[0012] In one embodiment of this application, after determining that the state of the thread to be detected is a potential deadlock state, the method further includes:

[0013] Get the status of multiple currently running first threads;

[0014] In each of the first threads, determine the second thread whose current state is abnormally blocked, and obtain the system call stack of each second thread, as well as the holding state of each second thread for multiple system locks;

[0015] If the system lock held by the thread under test is acquired in the reverse order of the system locks held by each of the second threads, the thread under test is determined to be in a deadlock state.

[0016] In one embodiment of this application,

[0017] The first blocking point is the system call stack of the thread under test at the current preset level, and the preset normal blocking point is the system call stack of the fixed blocking point of the thread under test at the preset level.

[0018] Secondly, embodiments of this application provide a detection device for thread abnormal blocking, applied to an embedded system, comprising:

[0019] The blocking point acquisition module is used to acquire the first blocking point of the thread to be detected that is currently in a blocked state;

[0020] The blocking point matching module is used to match the first blocking point with the preset normal blocking point of the thread to be detected;

[0021] The blocking state determination module is used to determine that the current state of the thread to be detected is an abnormal blocking state when the first blocking point fails to match the normal blocking point.

[0022] In one embodiment of this application, the apparatus further includes:

[0023] The state detection module is used to detect the abnormal duration of the thread under test being in an abnormal blocked state.

[0024] The state determination module is used to determine that the state of the thread to be detected is a potential deadlock state when the duration of the abnormality exceeds a preset time threshold.

[0025] In one embodiment of this application, the apparatus further includes:

[0026] The status acquisition module is used to acquire the status of multiple currently running first threads;

[0027] The abnormal thread determination module is used to determine the second thread in each of the first threads that is currently in an abnormal blocked state, and to obtain the system call stack of each of the second threads, as well as the holding state of each of the second threads for multiple system locks;

[0028] The deadlock determination module is used to determine that the state of the thread under test is deadlocked when the locking order of the system lock held by the thread under test is reversed with that of the system locks held by each of the second threads.

[0029] In one embodiment of this application,

[0030] The first blocking point is the system call stack of the thread under test at the current preset level, and the preset normal blocking point is the system call stack of the fixed blocking point of the thread under test at the preset level.

[0031] Thirdly, embodiments of this application provide an electronic device, including:

[0032] Memory, used to store computer programs;

[0033] The processor, when executing a program stored in memory, implements any of the above-described methods for detecting abnormal thread blocking.

[0034] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the above-described methods for detecting abnormal thread blocking.

[0035] This application also provides a computer program product containing instructions that, when run on a computer, cause the computer to execute any of the above-described methods for detecting abnormal thread blocking.

[0036] Beneficial effects of the embodiments in this application:

[0037] The thread abnormal blocking detection method, apparatus, and electronic device provided in this application are applied to embedded systems. First, a first blocking point of the thread to be detected, currently in a blocked state, is obtained. The first blocking point is then matched with a preset normal blocking point of the thread to be detected. If the first blocking point fails to match the normal blocking point, the current state of the thread to be detected is determined to be abnormally blocked. By pre-observing fixed blocking points where normal blocking would occur during thread operation, when the thread enters a blocked state, the current blocking position is compared with the fixed blocking position. If they do not match, the current blocking state of the thread can be determined to be abnormally blocked. This eliminates the need for complex calculations of the resources called by the thread, reducing the complexity and computational difficulty of thread abnormal blocking detection. Applied to the underlying system layer, compared to the method of calculating interface call time by embedding points at the application layer, it is more suitable for embedded systems with limited computing power and memory resources. Even other systems with abundant computing resources can achieve simpler detection of thread abnormal blocking through the method provided in this application.

[0038] Of course, implementing any product or method of this application does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description

[0039] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other embodiments can be obtained based on these drawings.

[0040] Figure 1-1 This is a schematic diagram of the first method for detecting thread abnormal blocking according to an embodiment of this application;

[0041] Figure 1-2 This is an example diagram of the function call stack in an embodiment of this application;

[0042] Figure 2-1 This is a schematic diagram of a second method for detecting thread abnormal blocking according to an embodiment of this application;

[0043] Figure 2-2 This is an example diagram of a thread deadlock state in an embodiment of this application;

[0044] Figure 3-1 This is a schematic diagram of one possible implementation of step S202 in an embodiment of this application;

[0045] Figure 3-2 This is a flowchart illustrating a method for detecting thread abnormal blocking according to an embodiment of this application.

[0046] Figure 4This is a schematic diagram of the structure of a thread abnormal blocking detection device according to an embodiment of this application;

[0047] Figure 5 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. Detailed Implementation

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

[0049] Due to the limited computing resources in embedded systems, it is difficult to detect abnormal thread blocking through application-layer instrumentation. To address this issue, this application provides a method for detecting abnormal thread blocking. This method can be executed by an electronic device, specifically, any device equipped with an embedded system.

[0050] The following provides a detailed description of the thread abnormal blocking detection method provided in the embodiments of this application. See also... Figure 1-1 , Figure 1-1 This is a flowchart illustrating a first method for detecting thread abnormal blocking according to an embodiment of this application, applied to an embedded system, including:

[0051] Step S101: Obtain the first blocking point of the thread to be detected that is currently in a blocked state.

[0052] A thread's blocked state refers to a state in which execution is suspended due to waiting for certain specific events to occur. Common reasons for blocking include: waiting for I / O (input / output) operations to complete, i.e., when a thread initiates an I / O request (such as reading a file, network communication, etc.), if the data is not yet ready, the thread will block at the I / O operation until the data is available; waiting for a specific condition variable, i.e., waiting for a certain condition variable to be met before it can continue running, and if the condition is not met, the thread will enter a blocked state during the waiting process; lock contention, i.e., in a multi-threaded environment, when a thread tries to acquire a lock that is already held by another thread, it will block at the lock acquisition operation until the lock is released.

[0053] Specifically, thread locks are used to protect shared resources, ensuring that in a multi-process or multi-threaded environment, only one thread can access a specific shared resource at a time, preventing data races and inconsistencies. The thread locking process includes requesting the lock, waiting for the lock, and releasing the lock. Requesting the lock means that when a thread needs to access a shared resource, it initiates a lock request for that resource. If the shared resource is not currently accessed, meaning the lock is not held, the thread acquires control of the lock, the lock acquisition is successful, and it begins accessing the shared resource. Waiting for the lock means that when the lock is held by another thread, the thread that initiated the lock request is blocked and enters a waiting state, waiting until the thread holding the lock releases it. Releasing the lock means that when the thread holding the lock completes its access to the shared resource, it performs an unlock operation, releasing control of the lock. One of the other threads in the waiting (blocked) state is awakened and acquires control of the lock, thus beginning access to the shared resource.

[0054] The system retrieves the first blocking point of the thread under test that is currently in a blocked state. The first blocking point represents the actual location where the thread under test is blocked. Specifically, all threads in the system that are in a blocked state are polled at regular intervals, such as 10 seconds, 30 seconds, etc., depending on the actual scenario requirements.

[0055] For example, an embedded system can have an exception detection module, in which cm_backtrace (an open source library for error tracing) can be ported and its call stack retrieval function can be called to obtain the first blocking point of the thread to be detected.

[0056] Step S102: Match the first blocking point with the preset normal blocking point of the thread to be detected.

[0057] Thread blocking includes normal blocking and abnormal blocking. Normal blocking refers to a thread actively entering a blocked state during execution due to reasonable business needs or system resource access rules. This is the expected behavior in program design, such as waiting for I / O operations to complete or waiting for specific condition variables. Abnormal blocking refers to a thread entering a blocked state due to unexpected or erroneous situations. This blocking is not the intention of program design and may lead to program failures or performance problems.

[0058] In a multithreaded environment, the most common cause of abnormal blocking is that multiple threads do not perform locking operations in the normal locking order. The normal locking order refers to arranging the locking operations of each process on each shared resource in the order required by each thread and the result of the execution, so that each process can run smoothly.

[0059] The normal blocking point of the thread under test, also known as the fixed blocking point of the thread under test, refers to the position where normal blocking occurs during the execution of the thread, which is obtained in advance based on the normal operating state of the thread under test.

[0060] For example, in implementing thread design, a thread might be blocked in a function after completing its business processing, yielding the processor to achieve reasonable CPU (central processing unit) utilization across multiple threads. This can be achieved through methods such as message queues and semaphores. The thread waits in a message queue; if there are new messages, the thread retrieves them and processes them; otherwise, it remains blocked. This blocking is normal.

[0061] The first blocking point is matched with the normal blocking point of the thread to be detected to determine whether the blocking state of the thread to be detected that is blocked at the first blocking point is a normal blocking state.

[0062] Step S103: If the first blocking point fails to match the normal blocking point, the current state of the thread to be detected is determined to be an abnormal blocking state.

[0063] If the first blocking point fails to match the normal blocking point, it means that the blocking state of the thread under test that is blocked at the first blocking point is not normal blocking, and the current state of the thread under test is determined to be abnormal blocking state.

[0064] In one embodiment of this application, the first blocking point is the system call stack of the thread under test at the current preset level, and the preset normal blocking point is the system call stack of the fixed blocking point of the thread under test at the preset level.

[0065] The system call stack of the thread under test refers to the functions called by the thread during its execution, such as... Figure 1-2 As shown. When the thread to be monitored includes calls to functions A, B, C, and D in succession, the system call stack is the call stack of functions A, B, C, and D. A blocking point can be represented by a blocking point ID (identification code). The blocking point ID is the function call stack corresponding to the current blocking position. Specifically, the level of the function call stack before the blocking position corresponding to the blocking point ID is preset. For example, when the preset level is two, if the thread to be monitored is blocked while calling function C, the blocking point ID is functions B and C; when the preset level is three, if the thread to be monitored is blocked while calling function C, the blocking point ID is functions A, B, and C.

[0066] In one example, the function call stack represents the execution order of function calls; in a computer, it is represented by addresses in the program's address space corresponding to the functions. Figure 1-2The example shown is merely an illustration and does not represent the actual function call relationships. The system call stack is represented by a 32-bit array in a computer. This array can be pre-registered as the blocking point IDs of threads. After obtaining the ID of the first blocking point (system call stack), the ID of the first blocking point is compared with the ID of the fixed blocking point of the thread to be tested.

[0067] The thread abnormal blocking detection method provided in this application embodiment is applied to an embedded system. First, it obtains the first blocking point of the thread to be detected, which is currently in a blocked state. Then, it matches the first blocking point with a preset normal blocking point for the thread to be detected. If the first blocking point fails to match the normal blocking point, the current state of the thread to be detected is determined to be abnormally blocked. By pre-observing fixed blocking points where normal thread blocking would occur during normal operation, when the thread enters a blocked state, the current blocking position is compared with the fixed blocking position. If they do not match, the current blocking state of the thread can be determined to be abnormally blocked. This eliminates the need for complex calculations of the resources called by the thread, reducing the complexity and computational difficulty of thread abnormal blocking detection. Applied to the underlying system layer, compared to the method of calculating interface call time by embedding points at the application layer, it is more suitable for embedded systems with limited computing power and memory resources. Even other systems with abundant computing resources can use the method provided in this application embodiment to achieve simpler detection of thread abnormal blocking.

[0068] In one embodiment of this application, such as Figure 2-1 As shown, after determining that the current state of the thread to be detected is abnormally blocked, the method further includes:

[0069] Step S201: Detect the abnormal duration of the state of the thread to be detected as an abnormal blocked state;

[0070] Step S202: If the duration of the abnormality exceeds a preset time threshold, the state of the thread to be detected is determined to be a potential deadlock state.

[0071] A deadlock occurs when multiple threads are in a circular waiting state, each waiting for the other to release resources, preventing all related threads from continuing execution. For example... Figure 2-2 As shown, thread A holds resource R1 and requests resource R2, while thread B holds resource R2 and requests resource R1. Lock A for resource R1 and lock B for resource R2 are mutex locks. Since both threads A and B need to acquire the other's resources, threads A and B get stuck in a deadlock.

[0072] A potential deadlock state refers to a state where deadlock may occur, requiring further assessment. After determining that the current state of the thread under test is abnormally blocked, the duration of the abnormally blocked state is checked. If it exceeds a preset time threshold, the state of the thread under test is determined to be a potential deadlock state.

[0073] The thread abnormal blocking detection method provided in this application determines that the current state of the thread to be detected is abnormally blocked, and then detects the duration of the abnormal blocking state of the thread to be detected. If it exceeds a preset time threshold, the state of the thread to be detected is determined to be a potential deadlock state, so as to further judge and process the abnormally blocked thread in a timely manner, and avoid the problem that the thread deadlock causes the blocking time to be too long, which in turn leads to system failure.

[0074] In one embodiment of this application, such as Figure 3-1 As shown, after determining in step S202 that the state of the thread to be detected is a potential deadlock state, the method further includes:

[0075] Step S301: Obtain the status of the multiple currently running first threads;

[0076] Step S302: In each of the first threads, determine the second thread whose current state is abnormally blocked, and obtain the system call stack of each second thread, as well as the holding state of each second thread for multiple system locks;

[0077] Step S303: If the system lock held by the thread to be detected has the opposite locking order to the system locks held by each of the second threads, the thread to be detected is determined to be in a deadlock state.

[0078] After determining that the state of the thread to be detected is a potential deadlock state, the states of multiple currently running first threads are obtained, and each first thread is all the currently running threads.

[0079] Identify all threads that experienced abnormal blocking within the first thread, thus obtaining the second thread. Obtain the system call stack of the second thread, as well as the holding status of each second thread for multiple system locks. Specifically, the current holding status of all system locks by each thread can be obtained through the system lock status printing information in the system log, while simultaneously obtaining the holding status of the thread to be tested for each system lock.

[0080] By analyzing the system call stacks (function call relationships) of each thread and the states of each system lock, if the system lock held by the thread under test is acquired in the reverse order of locks held by other abnormally blocked threads (i.e., the thread under test and other abnormally blocked threads are mutually waiting for the lock held by the other), the state of the thread under test is determined to be deadlocked. Based on this, the target thread causing the deadlock can be identified, and both that thread and the thread under test can be dealt with.

[0081] The thread abnormal blocking detection method provided in this application determines the state of the thread under test as deadlocked when the locking order of the system lock held by the thread under test is reversed with that of the system lock held by the second thread. This allows for timely processing of threads in deadlocked state and avoids system failures caused by prolonged thread deadlock.

[0082] In one embodiment of this application, an example of the flow of the thread abnormal blocking detection method is as follows: Figure 3-2 As shown. After starting, first register a normal blocking point ID for each thread. If the thread polling times out, obtain all thread blocking points and match all thread blocking points with the registered blocking points. If there is a thread that does not match the registered blocking point, and this thread has been blocked at this blocking point for a timeout, then print the call stack and lock status of all threads at this moment to analyze whether a deadlock has occurred.

[0083] See Figure 4 This application also provides a detection device for thread abnormal blocking, applied to an embedded system, including:

[0084] The blocking point acquisition module 401 is used to acquire the first blocking point of the thread to be detected that is currently in a blocked state;

[0085] The blocking point matching module 402 is used to match the first blocking point with the preset normal blocking point of the thread to be detected;

[0086] The blocking state determination module 403 is used to determine that the current state of the thread to be detected is an abnormal blocking state when the first blocking point fails to match the normal blocking point.

[0087] The thread abnormal blocking detection device provided in this application embodiment is applied to an embedded system. It first obtains the first blocking point of the thread to be detected, which is currently in a blocked state; it then matches the first blocking point with a preset normal blocking point of the thread to be detected; if the first blocking point fails to match the normal blocking point, the current state of the thread to be detected is determined to be abnormally blocked. By pre-observing fixed blocking points where normal blocking would occur during thread operation, when the thread enters a blocked state, the current blocking position is compared with the fixed blocking position. If they do not match, the current blocking state of the thread can be determined to be abnormally blocked. This eliminates the need for complex calculations of the resources called by the thread, reducing the complexity and computational difficulty of thread abnormal blocking detection. Applied to the underlying system layer, compared to the method of calculating interface call time by embedding points at the application layer, it is more suitable for embedded systems with limited computing power and memory resources. Even other systems with abundant computing resources can achieve simpler detection of thread abnormal blocking through the method provided in this application embodiment.

[0088] In one embodiment of this application, the apparatus further includes:

[0089] The state detection module is used to detect the abnormal duration of the thread under test being in an abnormal blocked state.

[0090] The state determination state is used to determine that the state of the thread to be detected is a potential deadlock state when the duration of the abnormality exceeds a preset time threshold.

[0091] The thread abnormal blocking detection device provided in this application determines that the current state of the thread to be detected is abnormally blocked, and then detects the duration of the abnormal blocking state of the thread to be detected. If it exceeds a preset time threshold, the state of the thread to be detected is determined to be a potential deadlock state, so as to further judge and process the abnormally blocked thread in a timely manner, and avoid the problem that the thread deadlock causes the blocking time to be too long, which in turn leads to system failure.

[0092] In one embodiment of this application, the apparatus further includes:

[0093] The status acquisition module is used to acquire the status of multiple currently running first threads;

[0094] The abnormal thread determination module is used to determine the second thread in each of the first threads that is currently in an abnormal blocked state, and to obtain the system call stack of each of the second threads, as well as the holding state of each of the second threads for multiple system locks;

[0095] The deadlock determination module is used to determine that the state of the thread under test is deadlocked when the locking order of the system lock held by the thread under test is reversed with that of the system locks held by each of the second threads.

[0096] The thread abnormal blocking detection device provided in this application determines that the thread under test is in a deadlock state when the locking order of the system lock held by the thread under test is reversed with that of the system lock held by the second thread. This enables timely processing of threads in a deadlock state and avoids system failures caused by prolonged thread deadlock.

[0097] In one embodiment of this application,

[0098] The first blocking point is the system call stack of the thread under test at the current preset level, and the preset normal blocking point is the system call stack of the fixed blocking point of the thread under test at the preset level.

[0099] In the technical solution of this application, the operations of acquiring, storing, using, processing, transmitting, providing and disclosing system operation information are all carried out under authorized conditions.

[0100] This application also provides an electronic device, such as... Figure 5 As shown, it includes:

[0101] Memory 501 is used to store computer programs;

[0102] When processor 502 executes a program stored in memory 501, it implements any of the thread abnormal blocking detection methods described above.

[0103] Furthermore, the aforementioned electronic device may also include a communication bus and / or a communication interface, with the processor 502, communication interface, and memory 501 communicating with each other via the communication bus.

[0104] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.

[0105] The communication interface is used for communication between the aforementioned electronic devices and other devices.

[0106] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.

[0107] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0108] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the steps of the above-described method for detecting abnormal blocking of any thread.

[0109] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute the detection method for abnormal blocking of any thread in the above embodiments.

[0110] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a solid-state drive (SSD), etc.

[0111] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0112] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0113] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.

Claims

1. A method for detecting thread abnormal blocking, applied to an embedded system, characterized in that, include: Find the first blocking point of the thread to be detected that is currently in a blocked state; The first blocking point is matched with the preset normal blocking point of the thread to be detected; If the first blocking point fails to match the normal blocking point, the current state of the thread to be detected is determined to be an abnormal blocking state.

2. The method according to claim 1, characterized in that, After determining that the current state of the thread to be detected is abnormally blocked, the method further includes: The abnormal duration during which the state of the thread to be detected is abnormally blocked; If the duration of the abnormality exceeds a preset time threshold, the state of the thread to be detected is determined to be a potential deadlock state.

3. The method according to claim 2, characterized in that, After determining that the state of the thread to be detected is a potential deadlock state, the method further includes: Get the status of multiple currently running first threads; In each of the first threads, determine the second thread whose current state is abnormally blocked, and obtain the system call stack of each second thread, as well as the holding state of each second thread for multiple system locks; If the system lock held by the thread under test is acquired in the reverse order of the system locks held by each of the second threads, the thread under test is determined to be in a deadlock state.

4. The method according to claim 1, characterized in that, The first blocking point is the system call stack of the thread under test at the current preset level, and the preset normal blocking point is the system call stack of the fixed blocking point of the thread under test at the preset level.

5. A detection device for thread abnormal blocking, applied to an embedded system, characterized in that, include: The blocking point acquisition module is used to acquire the first blocking point of the thread to be detected that is currently in a blocked state; The blocking point matching module is used to match the first blocking point with the preset normal blocking point of the thread to be detected; The blocking state determination module is used to determine that the current state of the thread to be detected is an abnormal blocking state when the first blocking point fails to match the normal blocking point.

6. The apparatus according to claim 5, characterized in that, The device further includes: The state detection module is used to detect the abnormal duration of the thread under test being in an abnormal blocked state. The state determination module is used to determine that the state of the thread to be detected is a potential deadlock state when the duration of the abnormality exceeds a preset time threshold.

7. The apparatus according to claim 6, characterized in that, The device further includes: The status acquisition module is used to acquire the status of multiple currently running first threads; The abnormal thread determination module is used to determine the second thread in each of the first threads that is currently in an abnormal blocked state, and to obtain the system call stack of each of the second threads, as well as the holding state of each of the second threads for multiple system locks; The deadlock determination module is used to determine that the state of the thread under test is deadlocked when the locking order of the system lock held by the thread under test is reversed with that of the system locks held by each of the second threads.

8. The apparatus according to claim 5, characterized in that, The first blocking point is the system call stack of the thread under test at the current preset level, and the preset normal blocking point is the system call stack of the fixed blocking point of the thread under test at the preset level.

9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the method described in any one of claims 1-4.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described in any one of claims 1-4.