Abnormal detection method and device for semaphore of multi-threaded operating system

By introducing a semaphore linked list queue to manage thread state in a multi-threaded operating system, automated exception detection is realized, which solves the problem that traditional manual detection is difficult to meet the needs of complex systems and improves system stability.

CN114840425BActive Publication Date: 2025-02-18PINGJIE ELECTRONIC TECHNOLOGY (JIANGSU) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210508463.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-11
Publication Date
2025-02-18
Estimated Expiration
2042-05-11

AI Technical Summary

Technical Problem

In traditional multi-threaded operating systems, manual inspection and testing are difficult to meet the abnormal detection requirements of complex systems, resulting in the system's possible thread operation blockage, affecting stability.

Method used

It provides an abnormal detection method for semaphores of multi-threaded operating system. By receiving semaphores, obtaining and releasing instructions, using semaphore linked list queue to manage thread status, automatically detect thread exceptions, and prevent thread blocking.

Benefits of technology

It realizes automated exception detection of multi-threaded operating systems, improves system stability, and prevents thread operation blockage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114840425B_ABST
    Figure CN114840425B_ABST
Patent Text Reader

Abstract

The present application relates to a method and device for detecting abnormality of semaphores in a multi-threaded operating system, which can receive a semaphore acquisition instruction; when a first semaphore identifier exists in a semaphore linked list queue, add a thread to be executed to the tail of the first thread linked list queue; when a second thread identifier to be executed does not exist in the first thread linked list queue, obtain the first thread identifier of a thread in the first thread linked list queue whose thread state is running; traverse the semaphore linked list queue, and when a first thread identifier exists in a second thread linked list queue and the thread state is blocked, obtain the second thread identifier of a thread in the second thread linked list queue whose thread state is running; when a second thread identifier exists in the first thread linked list queue, prompt that an abnormality has occurred in the detection. The method can automatically detect abnormalities of threads, prevent thread operation blocking in a multi-threaded operating system, and improve the stability of the operation of the multi-threaded operating system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of computer multi-threaded operating systems, and in particular to a method, device, computer equipment, storage medium and computer program product for detecting abnormality of semaphores in a multi-threaded operating system. Background Art

[0002] Semaphore is a mechanism used by embedded multi-threaded operating systems to protect critical resources. Critical resources refer to resources that can only be occupied by one process or thread. Semaphores are responsible for coordinating various threads to ensure that they can use common resources correctly and reasonably. Mutual exclusion refers to the indirect constraint relationship between processes or threads. When a process enters the critical section to use critical resources, another process or thread must wait. Only when the process using critical resources exits the critical section will the process or thread be unblocked. In various traditional operating systems, mutex semaphores are generally used to protect critical resources. If in the process of using mutex semaphores implemented by software, a task exits after obtaining the mutex semaphore without releasing it, other tasks that come to obtain the mutex semaphore will always be blocked on the mutex semaphore, which will cause the system to work abnormally.

[0003] In traditional technology, manual inspection and testing are usually used to discover anomalies in multi-threaded operating systems. However, as the functions of multi-threaded operating systems gradually become richer, the workload of software development for multi-threaded operating systems is becoming increasingly large, and there may also be a situation of collaborative division of labor in the software development of multi-threaded operating systems. The previous manual detection methods have gradually failed to meet the needs of traditional multi-threaded operating system anomaly detection. Summary of the invention

[0004] Based on this, it is necessary to provide a multi-threaded operating system semaphore anomaly detection method, device, computer equipment, storage medium and computer program product that can automatically perform anomaly detection in response to the above technical problems.

[0005] In a first aspect, the present application provides a method for detecting anomalies of semaphores in a multi-threaded operating system, the method comprising:

[0006] Receive a semaphore acquisition instruction; wherein the semaphore acquisition instruction includes a first semaphore identifier and a corresponding thread to be executed, and the thread to be executed includes a thread to be executed identifier;

[0007] When the first semaphore identifier exists in the pre-stored semaphore linked list queue, adding the to-be-executed thread to the tail of the first thread linked list queue corresponding to the first semaphore identifier;

[0008] When the second thread identifier to be executed exists in the first thread linked list queue, a prompt is given that a detection abnormality occurs;

[0009] When the second to-be-executed thread identifier does not exist in the first thread linked list queue, obtaining a first thread identifier of a thread in the first thread linked list queue whose thread state is running;

[0010] Traversing the thread linked list queues corresponding to other semaphore identifiers in the semaphore linked list queue except the first thread linked list queue, and when the first thread identifier exists in the second thread linked list queue and the thread state is blocked, obtaining the second thread identifier of the thread in the second thread linked list queue whose thread state is running;

[0011] When the second thread identifier exists in the first thread linked list queue, it is prompted that detection is abnormal.

[0012] In one embodiment, after the step of receiving the semaphore acquisition instruction, the step further includes:

[0013] When the first semaphore identifier does not exist in the pre-stored semaphore linked list queue, creating a third thread linked list queue corresponding to the first semaphore identifier;

[0014] The to-be-executed thread is added to the third thread linked list queue, and a prompt is given that no abnormality is detected.

[0015] In one embodiment, after the step of traversing the thread linked list queues corresponding to other semaphore identifiers in the semaphore linked list queue except the first thread linked list queue, the step further includes:

[0016] When the first thread identifier does not exist in the thread linked list queues corresponding to other semaphore identifiers, it is prompted that no abnormality occurs in the detection.

[0017] In one embodiment, it also includes:

[0018] Receive a semaphore release instruction; wherein the semaphore release instruction includes a second semaphore identifier and a corresponding thread to be released, and the thread to be released includes a thread identifier to be released;

[0019] In the pre-stored semaphore linked list queue, the thread carrying the to-be-released thread identifier and the thread state being running in the fourth thread linked list queue is deleted, wherein the fourth thread linked list queue carries the second semaphore identifier;

[0020] When there is a next thread in the fourth thread linked list queue, updating the thread state of the next thread to running, and obtaining the third thread identifier of the thread;

[0021] When the second third thread identifier exists in the fourth thread linked list queue, it is prompted that the detection is abnormal;

[0022] When the second third thread identifier does not exist in the fourth thread linked list queue, traverse the thread linked list queues corresponding to other semaphore identifiers except the fourth thread linked list queue in the semaphore linked list queue, and when the third thread identifier exists in the fifth thread linked list queue and the thread state is blocked, obtain the fourth thread identifier of the thread in the fifth thread linked list queue whose thread state is running;

[0023] When the fourth thread identifier exists in the fourth thread linked list queue, it is prompted that detection is abnormal.

[0024] In one embodiment, after the step of deleting the thread carrying the to-be-released thread identifier and the thread state being running in the fourth thread linked list queue in the pre-stored semaphore linked list queue, the step further includes:

[0025] When there is no next thread in the fourth thread linked list queue, it is prompted that no abnormality occurs in the detection.

[0026] In one embodiment, the step of traversing the thread linked list queues corresponding to other semaphore identifiers in the semaphore linked list queue except the fourth thread linked list queue includes:

[0027] When the third thread identifier does not exist in the thread linked list queue corresponding to other semaphore identifiers, it is prompted that no abnormality occurs in the detection.

[0028] In a second aspect, the present application further provides a multi-threaded operating system semaphore abnormality detection device, the abnormality detection device comprising:

[0029] A receiving module receives a semaphore acquisition instruction; wherein the semaphore acquisition instruction includes a first semaphore identifier and a corresponding thread to be executed, and the thread to be executed includes a thread to be executed identifier;

[0030] An adding module, configured to add the to-be-executed thread to the tail of the first thread linked list queue corresponding to the first semaphore identifier when the first semaphore identifier exists in the pre-stored semaphore linked list queue;

[0031] A first prompt module, configured to prompt that detection is abnormal when there is a second thread identifier to be executed in the first thread linked list queue;

[0032] A first acquisition module, configured to acquire a first thread identifier of a thread in the first thread linked list queue whose thread state is running when the second thread identifier to be executed does not exist in the first thread linked list queue;

[0033] A second acquisition module is used to traverse the thread linked list queues corresponding to other semaphore identifiers in the semaphore linked list queue except the first thread linked list queue, and when the first thread identifier exists in the second thread linked list queue and the thread state is blocked, obtain the second thread identifier of the thread in the second thread linked list queue whose thread state is running;

[0034] The second prompt module is used to prompt that detection is abnormal when the second thread identifier exists in the first thread linked list queue.

[0035] In a third aspect, the present application further provides a computer device, wherein the computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of the above-mentioned multi-threaded operating system semaphore abnormality detection method are implemented.

[0036] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, which implements the steps of the above-mentioned multi-threaded operating system semaphore abnormality detection method when executed by a processor.

[0037] In a fifth aspect, the present application further provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned multi-threaded operating system semaphore abnormality detection method are implemented.

[0038] The above-mentioned method, device, computer equipment, storage medium and computer program product for detecting abnormalities of semaphores in a multi-threaded operating system can automatically manage and detect each thread in the multi-threaded operating system. When the multi-threaded operating system receives a semaphore acquisition request or a semaphore release request, it can automatically detect thread abnormalities to prevent the multi-threaded operating system from experiencing thread operation blockage, thereby improving the stability of the multi-threaded operating system. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 A diagram of an application environment of a method for detecting abnormality of a semaphore in a multi-threaded operating system in one embodiment;

[0040] Figure 2 A schematic diagram of a flow chart of a method for detecting anomalies of semaphores in a multi-threaded operating system when a semaphore acquisition instruction is received in an embodiment;

[0041] Figure 3 A schematic diagram of a flow chart of a method for detecting anomalies of semaphores in a multi-threaded operating system when a semaphore acquisition instruction is received in another embodiment;

[0042] Figure 4A schematic diagram of a flow chart of a method for detecting anomalies of semaphores in a multi-threaded operating system when a semaphore release instruction is received in an embodiment;

[0043] Figure 5 A schematic diagram of a flow chart of a method for detecting anomalies of semaphores in a multi-threaded operating system when a semaphore release instruction is received in another embodiment;

[0044] Figure 6 A block diagram of a module structure for processing a semaphore acquisition instruction in a semaphore abnormality detection device for a multi-threaded operating system according to an embodiment;

[0045] Figure 7 A block diagram of a module structure for processing a semaphore release instruction in a semaphore abnormality detection device for a multi-threaded operating system according to an embodiment;

[0046] Figure 8 FIG. 4 is a structural block diagram of a computer device in one embodiment. DETAILED DESCRIPTION

[0047] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0048] The embodiment of the present application is based on technologies such as machine learning, and is capable of receiving a semaphore acquisition instruction; wherein the semaphore acquisition instruction includes a first semaphore identifier and a corresponding thread to be executed, and the thread to be executed includes a thread identifier to be executed; when the first semaphore identifier exists in a pre-stored semaphore linked list queue, the thread to be executed is added to the tail of the first thread linked list queue corresponding to the first semaphore identifier; when the second thread identifier to be executed exists in the first thread linked list queue, a prompt is given that an abnormality has occurred in the detection; when the second thread identifier to be executed does not exist in the first thread linked list queue, the first thread identifier of the thread in the first thread linked list queue whose thread state is running is obtained; the thread linked list queues corresponding to other semaphore identifiers in the semaphore linked list queue except the first thread linked list queue are traversed, and when the first thread identifier exists in the second thread linked list queue and the thread state is blocked, the second thread identifier of the thread in the second thread linked list queue whose thread state is running is obtained; when the second thread identifier exists in the first thread linked list queue, a prompt is given that an abnormality has occurred in the detection.

[0049] In the field of embedded applications, multi-threaded embedded operating systems (i.e., multi-threaded operating systems) are usually used to implement sequential responses of corresponding functions. Resources that can only be occupied by one thread in a multi-threaded operating system are called critical resources, and the area where critical resources are stored in a multi-threaded operating system is called a critical section. Semaphores, as a mechanism for protecting critical resources, are responsible for coordinating various threads to ensure that they can use common resources correctly and reasonably.

[0050] The states of threads are usually divided into five categories: new, ready, running, blocked and dead. Among them, the transition between the three states of ready, running and blocked can be controlled according to the request or release operation of the semaphore.

[0051] When a thread enters the critical section and uses the critical resource, the thread state of the thread is updated to running. The subsequent thread that uses the critical resource must enter the queue and wait for the critical resource to be released. At this time, the thread state of the waiting thread in the queue is updated to blocked. Only when the thread with the running thread state exits the critical section, the thread state of the next thread in the waiting queue will be updated to running. This indirect constraint relationship between threads is called mutual exclusion. Threads that have a mutual exclusion relationship with each other are called mutually exclusive threads. The semaphore containing mutually exclusive threads is called a mutual exclusion semaphore. In various traditional operating systems, mutual exclusion semaphores can be used to protect critical resources. It should be noted that the semaphores described below are all mutual exclusion semaphores by default.

[0052] The multi-threaded operating system semaphore anomaly detection method provided in this application can be applied to Figure 1In the application environment shown, the application environment provides at least one terminal 102, a server 104 and a data storage system, wherein the terminal 102 communicates with the server 104 through a network, the data storage system can store data that the server 104 needs to process, and the data storage system can be integrated on the server 104, or placed on a cloud or other network server. The anomaly detection method can be applied to any terminal 102 or server 104, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. For example, the server 104 receives a semaphore acquisition instruction issued by any terminal 102; when a first semaphore identifier exists in the pre-stored semaphore linked list queue, the server 104 adds a thread to be executed to the tail of the first thread linked list queue corresponding to the first semaphore identifier; when a second thread identifier to be executed exists in the first thread linked list queue, the server 104 prompts the terminal 102 that issues the semaphore acquisition instruction through network control that an abnormality has occurred in the detection; when the second thread identifier to be executed does not exist in the first thread linked list queue, the server 104 obtains the first thread identifier of the thread in the first thread linked list queue whose thread state is running; the server 104 traverses the thread linked list queues corresponding to other semaphore identifiers in the semaphore linked list queue except the first thread linked list queue, and when the first thread identifier exists in the second thread linked list queue and the thread state is blocked, the server 104 obtains the second thread identifier of the thread in the second thread linked list queue whose thread state is running; when the second thread identifier exists in the first thread linked list queue, the server 104 prompts the terminal 102 that issues the semaphore acquisition instruction through network control that an abnormality has occurred in the detection. Among them, the terminal can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be implemented as an independent server or a server cluster composed of multiple servers. The terminal 102 and the server 104 can be directly or indirectly connected through wired or wireless communication, such as through a network connection.

[0053] For another example, when receiving a semaphore acquisition instruction input by a user, terminal 102 obtains information of a pre-stored semaphore linked list queue from terminal 102; when a first semaphore identifier exists in the pre-stored semaphore linked list queue, terminal 102 adds a thread to be executed to the tail of a first thread linked list queue corresponding to the first semaphore identifier; when a second thread identifier to be executed exists in the first thread linked list queue, terminal 102 prompts that a detection abnormality has occurred; when a second thread identifier to be executed does not exist in the first thread linked list queue, terminal 102 obtains a first thread identifier of a thread in the first thread linked list queue whose thread state is running; terminal 102 traverses thread linked list queues corresponding to other semaphore identifiers in the semaphore linked list queue except the first thread linked list queue, and when a first thread identifier exists in the second thread linked list queue and the thread state is blocked, terminal 102 obtains a second thread identifier of a thread in the second thread linked list queue whose thread state is running; when a second thread identifier exists in the first thread linked list queue, terminal 102 prompts that a detection abnormality has occurred.

[0054] In one embodiment, Figure 2 As shown, a method for detecting anomalies of semaphores in a multi-threaded operating system is provided. This embodiment uses the application of the anomaly detection method to a server as an example. It can be understood that the method can also be applied to a terminal, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. In this embodiment, the anomaly detection method includes the following steps 202 to 212:

[0055] Step 202: Receive a semaphore acquisition instruction; wherein the semaphore acquisition instruction includes a first semaphore identifier and a corresponding thread to be executed, and the thread to be executed includes a thread identifier to be executed.

[0056] The semaphore acquisition instruction refers to the instruction issued by the terminal to obtain the semaphore corresponding to a pending thread. The pending thread refers to the thread that has not yet been assigned a semaphore. The semaphore refers to a mechanism that can be used to ensure that two or more code segments are not called concurrently. The thread refers to the smallest unit that can perform calculation scheduling in the operating system. It is contained in the process and is the actual operation unit in the process. A thread refers to a single sequential control flow in a process. Multiple threads can run concurrently in a process, and each thread executes different tasks in parallel. Before calling the corresponding code segment, the thread must obtain a semaphore. When the call of the code segment is completed, the thread will release the acquired semaphore.

[0057] The semaphore identifier is used to uniquely identify the semaphore. The semaphore identifier can be composed of at least one of letters, characters, or numbers. The thread identifier is used to uniquely identify the thread. The thread identifier can be composed of at least one of letters, characters, or numbers.

[0058] The first semaphore identifier is the identifier corresponding to the semaphore to be obtained by the semaphore acquisition instruction, and the pending thread identifier is the identifier corresponding to the pending thread. For example, the first semaphore identifier included in the semaphore acquisition instruction is S1D1, and the pending thread identifier carried by the pending thread is T1D1.

[0059] In this embodiment, the server receives a request from a terminal to allocate a corresponding semaphore to a thread that is about to call a code, i.e., a semaphore acquisition instruction, and further obtains the first semaphore identifier, the thread to be executed, and the thread identifier to be executed carried by the semaphore acquisition request, thereby determining the thread that needs to obtain the semaphore and the semaphore to be obtained by the thread.

[0060] Step 204: When the first semaphore identifier exists in the pre-stored semaphore linked list queue, add the thread to be executed to the tail of the first thread linked list queue corresponding to the first semaphore identifier.

[0061] The multi-threaded operating system in this embodiment includes a semaphore linked list queue, which includes a semaphore linked list head, at least one linked list element and a linked list tail, wherein the linked list element is used to represent a unique semaphore, wherein each linked list element corresponds to a thread linked list queue, and the linked list element carries, for example, a corresponding semaphore identifier and the total number of threads included in the corresponding thread linked list queue, and the thread linked list queue contains the thread identifier of at least one thread sorted in sequence. For example, the semaphore linked list queue includes linked list elements S1D1, S1D2, and S1D3, the thread linked list queue corresponding to the linked list element S1D1 contains threads T1D1 and T1D2, the thread linked list queue corresponding to the linked list element S1D2 contains threads T1D2 and T1D3, and the thread linked list queue corresponding to the linked list element S1D3 contains threads T1D1, T1D3, and T1D4.

[0062] The first thread linked list queue refers to the thread linked list queue corresponding to the linked list element carrying the first semaphore identifier.

[0063] In this embodiment, the server matches the first semaphore identifier with the semaphore identifiers carried by each linked list element in a pre-stored semaphore linked list queue, obtains the linked list element that carries the same semaphore identifier as the first semaphore identifier, and adds the thread to be executed to the tail of the thread linked list queue corresponding to the linked list element.

[0064] Step 206: When there is a second thread identifier to be executed in the first thread linked list queue, it is prompted that the detection is abnormal.

[0065] In the multi-threaded operating system of this embodiment, the server may repeatedly receive requests from the terminal to obtain the same semaphore for the same thread. In this case, when the request is received for the first time, the server adds the thread to the tail of the thread linked list queue corresponding to the semaphore. When the request is received for the second time, the server still adds the thread to the tail of the thread linked list queue corresponding to the semaphore. At this time, there are two identical threads in the thread linked list queue, and the two threads are arranged in the order in which the server receives the requests. When the thread with the highest order successfully obtains the semaphore, its thread state is updated to running. The thread with the lowest order is blocked because the semaphore is obtained by the thread with the highest order, that is, the current thread linked list queue is in a "zombie state", which will make the threads in the thread linked list queue unable to perform subsequent processing. For example, the first semaphore identifier included in the semaphore acquisition instruction is S1D1, the thread identifier to be executed carried by the thread to be executed is T1D1, and the thread linked list queue corresponding to the linked list element S1D1, that is, the first thread linked list queue contains threads T1D1 and T1D2. At this time, two threads T1D1 carrying the first semaphore identifier S1D1 appear in the first thread linked list queue at the same time, which prompts an exception.

[0066] In this embodiment, the server first obtains each thread in the first thread linked list queue except the thread to be executed, and matches the thread identifier to be executed with the thread identifier carried by each obtained thread. When a thread identifier that is the same as the thread identifier to be executed is matched, the server control terminal prompts that an abnormality has occurred in the detection.

[0067] It should be noted that the prompting methods may include signal light prompts, sound prompts, text prompts, buzzer prompts, etc. The setting is intended to prompt the staff of the corresponding test results through the terminal. This application does not limit the prompting method, and all prompting methods with the same purpose as this setting should be included in the protection scope of the present invention.

[0068] Step 208: When there is no second thread identifier to be executed in the first thread linked list queue, obtain the first thread identifier of the thread in the first thread linked list queue whose thread state is running.

[0069] The thread state is running, which refers to the thread that successfully obtains the current semaphore, that is, the thread that is ranked first in the current thread linked list queue. The first thread identifier refers to the identifier of the thread that successfully obtains the current semaphore.

[0070] In this embodiment, the server obtains each thread in the first thread linked list queue except the thread to be executed, and matches the thread identifier to be executed with the thread identifier carried by each obtained thread. When the thread identifier that is the same as the thread identifier to be executed is not matched, the server will use the thread identifier carried by the thread that successfully obtains the current semaphore as the first thread identifier.

[0071] Step 210, traverse the thread linked list queues corresponding to other semaphore identifiers in the semaphore linked list queue except the first thread linked list queue, and when the first thread identifier exists in the second thread linked list queue and the thread state is blocked, obtain the second thread identifier of the thread in the second thread linked list queue whose thread state is running.

[0072] The second thread linked list queue refers to the thread linked list queue where the thread carrying the same thread identifier as the first thread identifier and which has not successfully acquired the corresponding semaphore is located.

[0073] The second thread identifier refers to the identifier of the thread that successfully obtains the semaphore corresponding to the second thread linked list queue.

[0074] In this embodiment, the server excludes the first thread linked list queue, and matches the first thread identifier with the thread identifier carried by each thread in the thread linked list queues corresponding to the remaining semaphores. When a thread identifier that is the same as the first thread identifier is matched and the thread fails to successfully obtain the corresponding semaphore, the thread linked list queue where the thread is located is used as the second thread linked list queue, and the server uses the thread identifier carried by the thread that successfully obtains the corresponding semaphore in the second thread linked list queue as the second thread identifier.

[0075] Step 212: When the second thread identifier exists in the first thread linked list queue, it is prompted that the detection is abnormal.

[0076] In this embodiment, the server matches the second thread identifier with the thread identifier carried by the thread in the first thread linked list queue. When a thread identifier identical to the second thread identifier is matched, it is considered that the semaphore corresponding to the second thread linked list queue has received the acquisition instructions of the thread corresponding to the second thread identifier and the thread corresponding to the first thread identifier in sequence, and the semaphore corresponding to the first thread linked list queue has received the acquisition instructions of the thread corresponding to the first thread identifier and the thread corresponding to the second thread identifier in sequence. At this time, if the thread corresponding to the first thread identifier first obtains the semaphore corresponding to the second thread linked list queue, the thread corresponding to the first thread identifier will be blocked because the semaphore corresponding to the second thread linked list queue has not been released by the thread corresponding to the second thread identifier, and the server control terminal prompts that an abnormality has occurred in the detection; if the thread corresponding to the second thread identifier first obtains the semaphore corresponding to the first thread linked list queue, the thread corresponding to the second thread identifier will be blocked because the semaphore corresponding to the first semaphore identifier has not been released by the thread corresponding to the first thread identifier, and the server control terminal prompts that an abnormality has occurred in the detection. For example, when semaphore A in a multi-threaded operating system receives a semaphore acquisition instruction from thread S1 at time t, and then receives a semaphore acquisition instruction from thread S2, semaphore B receives a semaphore acquisition instruction from thread S2 at time t, and then receives a semaphore acquisition instruction from thread S1, then in this case, if thread S1 acquires semaphore B earlier than thread S2 acquires semaphore A, semaphore B has not been released by thread S2 at this time, and thread S1 is blocked halfway through its execution; if thread S2 acquires semaphore A first, semaphore A has not been released by thread S1 at this time, so thread S2 is blocked halfway through its execution.

[0077] In the above-mentioned abnormality detection method, the semaphore to be acquired by the thread to be executed, that is, the target semaphore, is confirmed by the first semaphore identifier carried by the semaphore acquisition instruction, and the semaphore identifier carried by the pre-stored semaphore linked list queue is matched with the first semaphore identifier to obtain the thread linked list queue corresponding to the target semaphore, that is, the first thread linked list queue, and the thread to be executed is added to the tail of the first thread linked list queue, and then the thread identifiers carried by the remaining threads in the first thread linked list queue are matched with the thread identifier to be executed, so as to determine whether there is a second thread to be executed in the first thread linked list queue, so as to detect whether the same thread obtains the same semaphore multiple times. In the event of an abnormal situation, if there is no second thread to be executed in the first thread linked list queue, the first thread identifier of the thread that has successfully obtained the target semaphore is further obtained, and it is determined whether the thread corresponding to the first thread identifier has subsequently obtained other semaphores, that is, the semaphore corresponding to the second thread linked list queue, and the second thread identifier of the thread that has successfully obtained the semaphore corresponding to the second thread linked list queue is obtained, and the thread identifier carried by the thread in the first thread linked list queue is matched with the second thread identifier, so as to determine whether the thread corresponding to the first thread identifier and the thread corresponding to the second thread identifier will be blocked when they are halfway through running, thereby completing the abnormality detection.

[0078] In one embodiment, the anomaly detection method further includes:

[0079] When the first semaphore identifier does not exist in the pre-stored semaphore linked list queue, a third thread linked list queue corresponding to the first semaphore identifier is created; the thread to be executed is added to the third thread linked list queue, and a prompt is given that no abnormality occurs in the detection.

[0080] The third thread linked list queue refers to a newly created thread linked list queue corresponding to the linked list element carrying the first semaphore identifier.

[0081] In this embodiment, when the semaphore identifiers carried by each linked list element in the pre-stored semaphore linked list queue are not the same as the first semaphore identifier, it is considered that the semaphore that the thread to be executed needs to obtain has not been obtained by other threads. At this time, the server creates a new linked list element in the semaphore linked list queue, and the linked list element carries the first semaphore identifier to represent the semaphore obtained by the thread to be executed.

[0082] In one embodiment, the anomaly detection method further includes:

[0083] When the first thread identifier does not exist in the thread linked list queues corresponding to other semaphore identifiers, it is prompted that no abnormality occurs in the detection.

[0084] In this embodiment, if the server does not match the thread identifier carried by the threads in the thread linked list queue corresponding to other semaphore identifiers with the same thread identifier as the first thread identifier, it is considered that the thread corresponding to the first thread identifier did not continue to acquire other semaphores subsequently. At this time, the server control terminal prompts that no abnormality has occurred in the detection.

[0085] like Figure 3 As shown, in one embodiment, the anomaly detection method includes:

[0086] Step a1, receiving a semaphore acquisition instruction; wherein the semaphore acquisition instruction includes a first semaphore identifier and a corresponding thread to be executed, and the thread to be executed includes a thread to be executed identifier.

[0087] Step a2, determining whether there is a first semaphore identifier in the pre-stored semaphore linked list queue;

[0088] Step a21: If it exists, add the thread to be executed to the tail of the first thread linked list queue corresponding to the first semaphore identifier, and execute step a3;

[0089] Step a22: If it does not exist, create a third thread linked list queue corresponding to the first semaphore identifier; add the thread to be executed to the third thread linked list queue, and execute step a6.

[0090] Step a3, determining whether there is a second thread to be executed in the first thread linked list queue;

[0091] If it exists, execute step a7;

[0092] Step a31: If it does not exist, obtain the first thread identifier of the thread whose thread state is running in the first thread linked list queue, and execute step a4.

[0093] Step a4: traverse the thread linked list queues corresponding to other semaphore identifiers in the semaphore linked list queue except the first thread linked list queue, and determine whether there is the first thread identifier in the second thread linked list queue and the thread state is blocked.

[0094] Step a41: If it exists, obtain the second thread identifier of the thread in the second thread linked list queue whose thread state is running, and execute step a5;

[0095] If not present, proceed to step a6.

[0096] Step a5, determining whether there is a second thread identifier in the first thread linked list queue;

[0097] If it exists, execute step a7;

[0098] If not present, proceed to step a6.

[0099] Step a6: The system prompts that no abnormality is found in the detection.

[0100] Step a7: The system prompts that an abnormality has occurred in the detection.

[0101] For example, the pre-stored semaphore linked list queue includes a total of three linked list elements, and the semaphore identifiers corresponding to these three linked list elements are S1D1, S1D2 and S1D3 respectively; the thread linked list queue corresponding to the linked list element with the semaphore identifier S1D1 includes a thread with a thread identifier T1D1 and a thread state of running and a thread with a thread identifier T1D2 and a thread state of blocked; the thread linked list queue corresponding to the linked list element with the semaphore identifier S1D2 includes a thread with a thread identifier T1D1 and a thread state of running and a thread with a thread identifier T1D2 and a thread state of blocked; the thread linked list queue corresponding to the linked list element with the semaphore identifier S1D3 includes a thread with a thread identifier T1D3 and a thread state of running, a thread with a thread identifier T1D1 and a thread state of blocked, and a thread with a thread identifier T1D4 and a thread state of blocked.

[0102] At this time, a semaphore acquisition instruction is received, and the first semaphore identifier corresponding to the semaphore acquisition instruction is S1D2, and the thread identifier of the thread to be executed is T1D3. The thread linked list queue corresponding to the linked list element with semaphore ID S1D2 is the first thread linked list queue. At this time, the thread to be executed T1D3 is added to the first thread linked list queue. At this time, the first thread linked list queue includes a thread with thread identifier T1D1 and a thread state of running, a thread with thread identifier T1D2 and a thread state of blocked, and a thread with thread identifier T1D3 and a thread state of blocked.

[0103] If there are no two threads with the same thread identifier in the first thread linked list queue, T1D1 is used as the first thread identifier, and the thread linked list queues corresponding to the other two linked list elements are traversed. The thread linked list queue corresponding to the linked list element with the semaphore identifier S1D3 is used as the second thread linked list queue, and T1D3 is used as the second thread identifier. It can be seen that there is a thread corresponding to the second thread identifier T1D3 in the first thread linked list queue, and the detection is abnormal.

[0104] like Figure 4 As shown, in one embodiment, the anomaly detection method further includes the following steps 302 to 314:

[0105] Step 302: Receive a semaphore release instruction; wherein the semaphore release instruction includes a second semaphore identifier and a corresponding thread to be released, and the thread to be released includes a thread identifier to be released.

[0106] The semaphore release instruction refers to an instruction issued by the terminal to release a semaphore corresponding to a thread to be executed, the thread to be released refers to a thread that has not yet released the semaphore, the second semaphore identifier refers to the identifier corresponding to the semaphore to be released by the semaphore release instruction, and the thread to be released identifier refers to the identifier corresponding to the thread to be released. For example, the first semaphore identifier included in the semaphore release instruction is S1D1, and the thread to be released carried by the thread to be released is T1D1.

[0107] In this embodiment, the server receives a request from the terminal to release the corresponding semaphore for a thread that ends a calling code, that is, a semaphore release instruction, and further obtains the second semaphore identifier, the thread to be released and the thread identifier to be released carried by the semaphore release request, thereby determining the thread that needs to release the semaphore and the semaphore to be released by the thread.

[0108] Step 304: In the pre-stored semaphore linked list queue, delete the thread in the fourth thread linked list queue that carries the thread identifier to be released and whose thread state is running, wherein the fourth thread linked list queue carries the second semaphore identifier.

[0109] The fourth thread linked list queue refers to the thread linked list queue corresponding to the linked list element carrying the same semaphore identifier as the second semaphore identifier.

[0110] In this embodiment, the server matches the second semaphore identifier with the semaphore identifiers carried by each linked list element in the pre-stored semaphore linked list queue, and uses the thread linked list queue of the matched linked list element as the fourth thread linked list queue. The server then matches the thread identifier to be released with the thread identifier carried by the thread in the fourth thread linked list queue, and deletes the matched thread when its thread state is running.

[0111] Step 306: When there is a next thread in the fourth thread linked list queue, update the thread state of the next thread to running, and obtain the third thread identifier of the thread;

[0112] In this embodiment, after deleting the thread carrying the thread identifier to be released and the thread state being running in the fourth thread linked list queue, the thread state of the next thread is updated to running according to the queuing order in the fourth thread linked list queue, and the thread identifier of the thread is used as the third thread identifier.

[0113] Step 308: When the second third thread identifier exists in the fourth thread linked list queue, it is prompted that the detection is abnormal.

[0114] In this embodiment, the server obtains each thread in the fourth thread linked list queue except the thread corresponding to the third thread identifier, and matches the third thread identifier with the thread identifier carried by each thread. When a thread identifier identical to the third thread identifier is matched, the server control terminal prompts that an abnormality has occurred in the detection.

[0115] Specifically, when the second third thread identifier exists in the fourth thread linked list queue, it indicates that the server repeatedly receives requests from the same thread to obtain the same semaphore. At this time, the server will be in a "zombie state", thereby causing the current thread linked list queue to be blocked.

[0116] Step 310: When there is no second third thread identifier in the fourth thread linked list queue, traverse the thread linked list queues corresponding to other semaphore identifiers except the fourth thread linked list queue in the semaphore linked list queue; when there is a third thread identifier in the fifth thread linked list queue and the thread state is blocked, obtain the fourth thread identifier of the thread in the fifth thread linked list queue whose thread state is running.

[0117] The fifth thread linked list queue refers to the thread linked list queue where the thread that carries the same thread identifier as the third thread identifier and has not successfully acquired the corresponding semaphore is located.

[0118] The fourth thread identifier refers to the identifier of the thread that successfully obtains the semaphore corresponding to the fifth thread linked list queue.

[0119] In this embodiment, the server excludes the fourth thread linked list queue, and matches the third thread identifier with the thread identifier carried by each thread in the thread linked list queues corresponding to the remaining semaphores. When a thread identifier that is the same as the third thread identifier is matched and the thread fails to successfully obtain the corresponding semaphore, the thread linked list queue where the thread is located is used as the fifth thread linked list queue, and the server uses the thread identifier carried by the thread that successfully obtains the corresponding semaphore in the fifth thread linked list queue as the fourth thread identifier.

[0120] Step 312: When the fourth thread identifier exists in the fourth thread linked list queue, it is prompted that the detection is abnormal.

[0121] In this embodiment, the server matches the fourth thread identifier with the thread identifier carried by the threads in the fourth thread linked list queue. When the thread identifier that is the same as the fourth thread identifier is matched, it is considered that the semaphore corresponding to the fourth thread linked list queue has received the acquisition instructions of the thread corresponding to the third thread identifier and the thread corresponding to the fourth thread identifier in sequence, and the semaphore corresponding to the fifth thread linked list queue has received the acquisition instructions of the thread corresponding to the fourth thread identifier and the thread corresponding to the third thread identifier in sequence. At this time, if the thread corresponding to the third thread identifier first obtains the semaphore corresponding to the fifth thread linked list queue, the thread corresponding to the third thread identifier will be blocked because the semaphore corresponding to the fifth thread linked list queue has not been released by the thread corresponding to the fourth thread identifier, and the server control terminal prompts that an abnormality has occurred in the detection; if the thread corresponding to the fourth thread identifier first obtains the semaphore corresponding to the fourth thread linked list queue identifier, the thread corresponding to the fourth thread identifier will be blocked because the semaphore corresponding to the fourth thread linked list queue has not been released by the thread corresponding to the third thread identifier, and the server control terminal prompts that an abnormality has occurred in the detection.

[0122] In the above-mentioned exception detection method, the semaphore to be acquired by the thread to be released is confirmed by the second semaphore identifier carried by the semaphore release instruction, and the semaphore identifier carried by the pre-stored semaphore linked list queue is matched with the second semaphore identifier to obtain the corresponding thread linked list queue, that is, the fourth thread linked list queue, and the thread in the fourth thread linked list queue whose thread state is running and whose thread identifier is the same as the thread identifier to be released is deleted, and then the thread state of the next thread in the fourth thread linked list queue is updated to running, and the thread identifier it carries is used as the third thread identifier, and the thread identifiers carried by the remaining threads in the fourth thread linked list queue are matched with the third thread identifier, so as to determine the fourth thread linked list queue. Whether there is a thread corresponding to the second and third thread identifiers in the queue, so as to detect whether there is an abnormal situation in which the same thread obtains the same semaphore multiple times. If there is no thread corresponding to the second and third thread identifiers in the fourth thread linked list queue, it is further determined whether the thread corresponding to the third thread identifier has also obtained other semaphores, that is, the semaphore corresponding to the fifth thread linked list queue, and the fourth thread identifier of the thread that has successfully obtained the semaphore corresponding to the fifth thread linked list queue is obtained, and the thread identifiers carried by all threads in the fourth thread linked list queue are matched with the fourth thread identifier, so as to determine whether the thread corresponding to the fourth thread identifier and the thread corresponding to the third thread identifier will be blocked when they are halfway through running, thereby completing the abnormality detection.

[0123] In one embodiment, the anomaly detection method further includes:

[0124] When there is no next thread in the fourth thread linked list queue, it is prompted that no abnormality occurs in the detection.

[0125] In this embodiment, after the server deletes the thread to be released corresponding to the semaphore release instruction, that is, releases the semaphore corresponding to the second semaphore identifier, if there is no next thread in the current thread linked list queue, it is considered that the semaphore will no longer be acquired by other threads in the future. At this time, the exception detection ends and a prompt is given that no exception occurs in the detection.

[0126] In one embodiment, the anomaly detection method further includes:

[0127] When the third thread identifier does not exist in the thread linked list queue corresponding to other semaphore identifiers, it is prompted that no abnormality occurs in the detection.

[0128] In this embodiment, if the server does not match the thread identifier carried by the threads in the thread linked list queue corresponding to other semaphore identifiers with the same thread identifier as the third thread identifier, it is considered that the thread corresponding to the third thread identifier does not continue to acquire other semaphores subsequently. At this time, the exception detection ends, and the server control terminal prompts that no abnormality occurs in the detection.

[0129] like Figure 5 As shown, in one embodiment, the anomaly detection method includes:

[0130] Step b1, receiving a semaphore release instruction; wherein the semaphore release instruction includes a second semaphore identifier and a corresponding thread to be released, and the thread to be released includes a thread identifier to be released.

[0131] Step b2: Determine whether there is a thread carrying a thread identifier to be released in the pre-stored semaphore linked list queue:

[0132] Step b3: If it exists, the thread linked list queue where the thread is located is used as the fourth thread linked list queue, and it is determined whether the thread state of the thread is running;

[0133] Step b31: If yes, delete the thread and execute step b4;

[0134] Otherwise, go to step b9.

[0135] Step b4: Determine whether there is a next thread in the fourth thread linked list queue:

[0136] Step b41: If it exists, update the thread state of the next thread to running, obtain the third thread identifier of the thread, and execute b5;

[0137] If not present, proceed to step b10.

[0138] Step b5: Determine whether there is a second third thread identifier in the fourth thread linked list queue:

[0139] If it exists, execute step b11;

[0140] Step b6: If it does not exist, traverse the thread linked list queues corresponding to the semaphore identifiers in the semaphore linked list queue except the fourth thread linked list queue to determine whether there is a thread carrying the third thread identifier:

[0141] Step b61: If yes, the thread linked list queue where the thread is located is used as the fifth thread linked list queue;

[0142] Step b7, determine whether the thread state of the thread is blocked;

[0143] Step b71: If yes, obtain the fourth thread identifier of the thread in the fifth thread linked list queue whose thread state is running, and execute step b8;

[0144] Otherwise, execute step b9.

[0145] Step b8, determining whether there is a fourth thread identifier in the fourth thread linked list queue;

[0146] If it exists, execute step b10;

[0147] If not present, proceed to step b11.

[0148] Step b9: a prompt appears indicating that there is no corresponding thread.

[0149] Step b10: It is prompted that no abnormality is found in the detection.

[0150] Step b11: a prompt is given that the detection is abnormal.

[0151] For example, the pre-stored semaphore linked list queue includes a total of three linked list elements, and the semaphore identifiers corresponding to these three linked list elements are S1D1, S1D2 and S1D3 respectively; the thread linked list queue corresponding to the linked list element with the semaphore identifier S1D1 includes a thread with a thread identifier T1D2 and a thread state of running and a thread with a thread identifier T1D1 and a thread state of blocked; the thread linked list queue corresponding to the linked list element with the semaphore identifier S1D2 includes a thread with a thread identifier T1D1 and a thread state of running and a thread with a thread identifier T1D2 and a thread state of blocked; the thread linked list queue corresponding to the linked list element with the semaphore identifier S1D3 includes a thread with a thread identifier T1D3 and a thread state of running, a thread with a thread identifier T1D1 and a thread state of blocked, and a thread with a thread identifier T1D4 and a thread state of blocked.

[0152] At this time, a semaphore release instruction is received, and the second semaphore identifier corresponding to the semaphore release instruction is S1D3, and the thread identifier of the thread to be released is T1D3. The thread linked list queue corresponding to the linked list element with semaphore ID S1D3 is the fourth thread linked list queue. At this time, the thread with thread identifier T1D3 in the fourth thread linked list queue is deleted, and the thread state of the thread with thread identifier T1D1 is updated to running, and the thread identifier T1D1 is used as the third thread identifier.

[0153] If there are no two threads with the same thread identifier in the fourth thread linked list queue, the thread linked list queues corresponding to the other two linked list elements are traversed, and the thread linked list queue corresponding to the linked list element with the semaphore identifier S1D1 is used as the fifth thread linked list queue, and T1D2 is used as the fourth thread identifier. It can be seen that there is no thread corresponding to the fourth thread identifier T1D2 in the fourth thread linked list queue, and it is prompted that no abnormality has occurred in the detection.

[0154] In this embodiment, through the automatic detection of the above steps, the abnormal states that may occur in the multi-threaded operating system can be detected in sequence during the operation of the multi-threaded operating system, eliminating the possibility of a "zombie state" in the multi-threaded operating system, improving the stability of the multi-threaded operating system and improving the safety.

[0155] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0156] Based on the same inventive concept, the embodiment of the present application also provides an abnormality detection device for implementing the above-mentioned abnormality detection method for multi-threaded operating system semaphores. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above-mentioned method, so the specific limitations in one or more abnormality detection device embodiments provided below can refer to the above-mentioned limitations on the abnormality detection method for multi-threaded operating system semaphores, and will not be repeated here.

[0157] In one embodiment, Figure 6As shown, a multi-threaded operating system semaphore abnormality detection device is provided, including a first receiving module 502, an adding module 504, a first prompting module 506, a first acquiring module 508, a second acquiring module 510 and a second prompting module 512, wherein:

[0158] The first receiving module 502 is used to receive a semaphore acquisition instruction; wherein the semaphore acquisition instruction includes a first semaphore identifier and a corresponding thread to be executed, and the thread to be executed includes a thread identifier to be executed;

[0159] An adding module 504 is used to add the to-be-executed thread to the tail of the first thread linked list queue corresponding to the first semaphore identifier when there is a first semaphore identifier in the pre-stored semaphore linked list queue;

[0160] A first prompt module 506 is used to prompt that a detection exception occurs when there is a second thread identifier to be executed in the first thread linked list queue;

[0161] A first acquisition module 508 is configured to acquire a first thread identifier of a thread in the first thread linked list queue whose thread state is running when there is no second thread identifier to be executed in the first thread linked list queue;

[0162] The second acquisition module 510 is used to traverse the thread linked list queues corresponding to other semaphore identifiers in the semaphore linked list queue except the first thread linked list queue, and when the first thread identifier exists in the second thread linked list queue and the thread state is blocked, obtain the second thread identifier of the thread in the second thread linked list queue whose thread state is running;

[0163] The second prompt module 512 is used to prompt that detection is abnormal when the second thread identifier exists in the first thread linked list queue.

[0164] In one embodiment, the multi-threaded operating system semaphore abnormality detection device further includes:

[0165] A creation module 514, configured to create a third thread linked list queue corresponding to the first semaphore identifier when the first semaphore identifier does not exist in the pre-stored semaphore linked list queue;

[0166] The third prompt module 516 is used to add the to-be-executed thread to the third thread linked list queue and prompt that no abnormality is detected.

[0167] In one embodiment, the multi-threaded operating system semaphore abnormality detection device further includes:

[0168] The fourth prompt module 518 is used to prompt that no abnormality occurs when the first thread identifier does not exist in the thread linked list queue corresponding to other semaphore identifiers, or when the first thread identifier exists in the second thread linked list queue and the thread state is running.

[0169] like Figure 7 As shown, in one embodiment, the abnormality detection device further includes a second receiving module 602, a deleting module 604, a third obtaining module 606, a fifth prompting module 608, a fourth obtaining module 610 and a sixth prompting module 612:

[0170] The second receiving module 602 is used to receive a semaphore release instruction; wherein the semaphore release instruction includes a second semaphore identifier and a corresponding thread to be released, and the thread to be released includes a thread identifier to be released;

[0171] The deleting module 604 is used to delete the threads carrying the to-be-released thread identifiers and whose thread status is running in the fourth thread linked list queue from the pre-stored semaphore linked list queue, wherein the fourth thread linked list queue carries the second semaphore identifier;

[0172] A third acquisition module 606, configured to update the thread state of the next thread to running when there is a next thread in the fourth thread linked list queue, and to acquire a third thread identifier of the thread;

[0173] A fifth prompting module 608 is configured to prompt that a detection abnormality occurs when a second third thread identifier exists in the fourth thread linked list queue;

[0174] The fourth acquisition module 610 is used for, when there is no second third thread identifier in the fourth thread linked list queue, traversing the thread linked list queues corresponding to other semaphore identifiers except the fourth thread linked list queue in the semaphore linked list queue, and when there is a third thread identifier in the fifth thread linked list queue and the thread state is blocked, acquiring the fourth thread identifier of the thread in the fifth thread linked list queue whose thread state is running;

[0175] The sixth prompt module 612 is used to prompt that detection is abnormal when there is a fourth thread identifier in the fourth thread linked list queue.

[0176] In one embodiment, the multi-threaded operating system semaphore abnormality detection device further includes:

[0177] The seventh prompt module 614 is used to prompt that no abnormality occurs in the detection when there is no next thread in the fourth thread linked list queue.

[0178] In one embodiment, the multi-threaded operating system semaphore abnormality detection device 100 further includes:

[0179] The eighth prompt module 616 is used to prompt that no abnormality occurs when the third thread identifier does not exist in the thread linked list queue corresponding to other semaphore identifiers, or when the third thread identifier exists in the fifth thread linked list queue and the thread state is running.

[0180] Each module in the above-mentioned multi-threaded operating system semaphore anomaly detection device can be implemented in whole or in part by software, hardware, or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each of the above modules.

[0181] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 8 As shown. The computer device includes a processor, a memory, a communication interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a method for detecting an abnormality of a multi-threaded operating system signal is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.

[0182] Those skilled in the art will understand that Figure 8 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0183] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0184] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.

[0185] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0186] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0187] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A method for detecting abnormality of semaphores in a multi-threaded operating system, characterized in that: The anomaly detection method comprises: Receive a semaphore acquisition instruction; wherein the semaphore acquisition instruction includes a first semaphore identifier and a corresponding thread to be executed, and the thread to be executed includes a thread to be executed identifier; When the first semaphore identifier exists in the pre-stored semaphore linked list queue, adding the to-be-executed thread to the tail of the first thread linked list queue corresponding to the first semaphore identifier; When the second thread identifier to be executed exists in the first thread linked list queue, a prompt is given that a detection abnormality occurs; When the second to-be-executed thread identifier does not exist in the first thread linked list queue, obtaining a first thread identifier of a thread in the first thread linked list queue whose thread state is running; Traversing the thread linked list queues corresponding to other semaphore identifiers in the semaphore linked list queue except the first thread linked list queue, and when the first thread identifier exists in the second thread linked list queue and the thread state is blocked, obtaining the second thread identifier of the thread in the second thread linked list queue whose thread state is running; When the second thread identifier exists in the first thread linked list queue, prompting that detection is abnormal; Wherein, after the step of receiving the semaphore acquisition instruction, the abnormality detection method further includes: When the first semaphore identifier does not exist in the pre-stored semaphore linked list queue, creating a third thread linked list queue corresponding to the first semaphore identifier; The to-be-executed thread is added to the third thread linked list queue, and a prompt is given that no abnormality is detected.

2. The anomaly detection method according to claim 1, characterized in that: After the step of traversing the thread linked list queues corresponding to other semaphore identifiers in the semaphore linked list queue except the first thread linked list queue, the following step further comprises: When the first thread identifier does not exist in the thread linked list queues corresponding to other semaphore identifiers, it is prompted that no abnormality occurs in the detection.

3. The abnormality detection method according to any one of claims 1 to 2, characterized in that: Also includes: Receive a semaphore release instruction; wherein the semaphore release instruction includes a second semaphore identifier and a corresponding thread to be released, and the thread to be released includes a thread identifier to be released; In the pre-stored semaphore linked list queue, the thread carrying the to-be-released thread identifier and the thread state being running in the fourth thread linked list queue is deleted, wherein the fourth thread linked list queue carries the second semaphore identifier; When there is a next thread in the fourth thread linked list queue, updating the thread state of the next thread to running, and obtaining the third thread identifier of the thread; When the second third thread identifier exists in the fourth thread linked list queue, it is prompted that the detection is abnormal; When the second third thread identifier does not exist in the fourth thread linked list queue, traverse the thread linked list queues corresponding to other semaphore identifiers except the fourth thread linked list queue in the semaphore linked list queue, and when the third thread identifier exists in the fifth thread linked list queue and the thread state is blocked, obtain the fourth thread identifier of the thread in the fifth thread linked list queue whose thread state is running; When the fourth thread identifier exists in the fourth thread linked list queue, it is prompted that detection is abnormal.

4. The anomaly detection method according to claim 3, characterized in that: After the step of deleting the thread carrying the to-be-released thread identifier and the thread state being running in the fourth thread linked list queue in the pre-stored semaphore linked list queue, the step further includes: When there is no next thread in the fourth thread linked list queue, it is prompted that no abnormality occurs in the detection.

5. The abnormality detection method according to claim 3, characterized in that: The step of traversing the thread linked list queues corresponding to other semaphore identifiers in the semaphore linked list queue except the fourth thread linked list queue comprises: When the third thread identifier does not exist in the thread linked list queue corresponding to other semaphore identifiers, it is prompted that no abnormality occurs in the detection.

6. A semaphore anomaly detection device for a multi-threaded operating system, characterized in that: The abnormality detection device comprises: A receiving module receives a semaphore acquisition instruction; wherein the semaphore acquisition instruction includes a first semaphore identifier and a corresponding thread to be executed, and the thread to be executed includes a thread to be executed identifier; An adding module, configured to add the to-be-executed thread to the tail of the first thread linked list queue corresponding to the first semaphore identifier when the first semaphore identifier exists in the pre-stored semaphore linked list queue; A first prompt module, configured to prompt that detection is abnormal when there is a second thread identifier to be executed in the first thread linked list queue; A first acquisition module, configured to acquire a first thread identifier of a thread in the first thread linked list queue whose thread state is running when the second thread identifier to be executed does not exist in the first thread linked list queue; A second acquisition module is used to traverse the thread linked list queues corresponding to other semaphore identifiers in the semaphore linked list queue except the first thread linked list queue, and when the first thread identifier exists in the second thread linked list queue and the thread state is blocked, obtain the second thread identifier of the thread in the second thread linked list queue whose thread state is running; A second prompt module, configured to prompt that a detection abnormality occurs when the second thread identifier exists in the first thread linked list queue; A creation module, used for creating a third thread linked list queue corresponding to the first semaphore identifier when the first semaphore identifier does not exist in the pre-stored semaphore linked list queue; The third prompt module is used to add the to-be-executed thread to the third thread linked list queue and prompt that no abnormality occurs during the detection.

7. The device for detecting abnormality of semaphores in a multi-threaded operating system according to claim 6, characterized in that: The abnormality detection device also includes: The fourth prompt module is used to prompt that no abnormality occurs when the first thread identifier does not exist in the thread linked list queue corresponding to other semaphore identifiers, or when the first thread identifier exists in the second thread linked list queue and the thread state is running.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method for detecting abnormality of a semaphore in a multi-threaded operating system according to any one of claims 1 to 5 are implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for detecting abnormality of a semaphore in a multi-threaded operating system according to any one of claims 1 to 5 are implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method for detecting abnormality of a semaphore in a multi-threaded operating system according to any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Information processing device and information processing method

    CN102906706A

  • Multi-thread calling method and device, computer system and storage medium

    CN111324465A