CN101295266A - Method, device and system for detecting and removing deadlock - Google Patents

Method, device and system for detecting and removing deadlock Download PDF

Info

Publication number
CN101295266A
CN101295266A CNA2008101115384A CN200810111538A CN101295266A CN 101295266 A CN101295266 A CN 101295266A CN A2008101115384 A CNA2008101115384 A CN A2008101115384A CN 200810111538 A CN200810111538 A CN 200810111538A CN 101295266 A CN101295266 A CN 101295266A
Authority
CN
China
Prior art keywords
resource
stack
deadlock
task
module
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CNA2008101115384A
Other languages
Chinese (zh)
Other versions
CN101295266B (en
Inventor
梁斌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Digital Technologies Chengdu Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN2008101115384A priority Critical patent/CN101295266B/en
Publication of CN101295266A publication Critical patent/CN101295266A/en
Application granted granted Critical
Publication of CN101295266B publication Critical patent/CN101295266B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The embodiment of the invention discloses a method for detecting and unlocking the deadlock. The method for detecting the deadlock comprises the following steps: a stack is arranged for the task; the resource marks of the resource which is obtained by the task are pressed in the stack; when the task releases the resource, the resource marks which are pressed in the stack pop up from the stack; that whether the resource marks of the resource released in the task and the resource marks which pop up from the stack is consistent or not is compared; if not, the deadlock appearance can be judged. The method for unlocking the deadlock comprises the following steps: the task running is stopped; the position of the resource mark where the deadlock happens is determined and taken as the deadlock position; the resources above the deadlock position are marked, pop up from the stack and are memorized; the resource mark where the deadlock occurs pops up and the resource where the deadlock occurs is released; the memorized resource mark is pressed back into the stack. The embodiment of the invention also provides a device and a system used for detecting and unlocking the deadlock and can discover the task deadlock in time, unlock the deadlock and improve the reliability of the software.

Description

Detect and remove the methods, devices and systems of deadlock
Technical field
The present invention relates to field of computer technology, relate in particular to a kind of methods, devices and systems that under the multitask situation, detect and remove deadlock.
Background technology
Along with development of computer, the technology of multitask, multithreading or multiprocessor is used very extensive at present.Described multitask is meant that then same program can have the path of several concurrent execution, and these task sharing memory address spaces can concurrent asynchronous execution.
Because the resource in the computing machine is limited,, need to guarantee to have only a task or a processor access shared resource in order to protect shared resource at every turn.The resource of using in the software is exactly a position in the shared drive, after a task is obtained resource, will resource mark be set in this core position, and at this moment, other tasks just can not be obtained this resource, but continues to wait for, up to obtaining this resource.This task uses after the described resource, need discharge resource operation, and other task just can be obtained this resource.
But the method improper use of resource just might cause deadlock.Usually, the situation that deadlock occurs has two kinds:
Situation one: two parallel tasks are arranged in same software, task 1 is obtained resource A, task 2 is obtained resource B simultaneously, before attempting discharging resource A, task 1 obtains resource B and task 2 is obtained resource A before attempting discharging resource B, so task 1 obtain resource B and task 2 obtain resource A can be not successful, and can wait always and stay, will cause deadlock like this.
Situation two: if a task has been obtained after the lock, do not discharge this lock, other tasks also just can't be obtained this lock, cause other tasks to move, and then cause deadlock.
In realizing process of the present invention, the inventor finds that there are the following problems in the prior art:
After deadlock situation occurring in the program, thus software will lose operation function and can't normally move, and then cause the reliability of software low, and cause damage to software users.
Summary of the invention
On the one hand, embodiments of the invention provide a kind of method and apparatus that detects deadlock, can detect the deadlock situation that occurs in the program, improve the reliability of software.
The method that embodiments of the invention detect deadlock is by the following technical solutions:
A kind of method that detects deadlock comprises:
For task is provided with stack;
The resource mark of the resource that described task obtained is pressed into stack successively;
When described task discharges described resource, the described resource mark that is pressed in the stack is ejected from stack;
Whether the resource mark of the resource that more described task discharges is consistent with the described resource mark that ejects from stack, if inconsistent, then judge deadlock takes place.
The device that embodiments of the invention detect deadlock is by the following technical solutions:
A kind of device that detects deadlock comprises:
Stack is provided with module, is used to task that stack is set;
Resource mark is pressed into module, and being used for when described stack is provided with module is after task is provided with stack, and the resource mark of the resource that described task obtained is pressed into stack successively;
The first resource mark pop-up module is used for when described task discharges described resource, described resource mark is pressed into the described resource mark that module is pressed in the stack ejects from stack;
First comparison module is used for when the described first resource mark module ejects resource mark, and whether the resource mark of the resource that more described task discharges is consistent with the described resource mark that ejects from stack.
Embodiments of the invention detect the method and apparatus of deadlock, for task is provided with stack, when task is obtained resource, the resource mark of resources available is pressed into stack successively, when task discharges resource, resource mark is ejected from stack, and whether whether consistent the detection task deadlock takes place the resource mark by relatively discharging resource with the described resource mark that ejects from stack.Compared with prior art, the present invention detects the method for deadlock can in time find the task deadlock when task discharges resource, improved the reliability of software.
On the other hand, embodiments of the invention provide another to detect the method and apparatus of deadlock, can detect the deadlock situation that occurs in the program, improve the reliability of software.
The method that embodiments of the invention detect deadlock is by the following technical solutions:
A kind of method that detects deadlock comprises:
For task is provided with stack;
The resource mark of the resource that described task obtained is pressed into stack, and described resource mark comprises the acquisition time of resource;
What described resource mark was set deposits the stack time threshold;
Obtain according to the acquisition time of current detection time and resource and to deposit the stack time;
Deposit the stack time and compare described,, then judge deadlock takes place if deposit the stack time greater than depositing the stack time threshold with the described stack time threshold of depositing.
The device that embodiments of the invention detect deadlock is by the following technical solutions:
A kind of device that detects deadlock comprises:
Stack is provided with module, is used to task that stack is set;
Resource mark is pressed into module, and being used for when stack is provided with module is after task is provided with stack, and the resource mark of the resource that described task obtained is pressed into stack, and described resource mark comprises the acquisition time of resource;
Time threshold is provided with module, and what be used to be provided with resource mark deposits the stack time threshold;
Deposit the stack time-obtaining module, be used for being pressed into the acquisition time of the resource in the resource mark that module is pressed into stack and obtaining current detection time and deposit the stack time according to described resource mark;
Second comparison module is used for depositing the stack time of depositing that the stack time-obtaining module obtains and comparing with the stack time threshold of depositing that described time threshold is provided with the module setting described.
Embodiments of the invention detect the method and apparatus of deadlock, for task is provided with stack, when task is obtained resource, the resource mark of resources available are pressed into stack, and described resource mark comprises the acquisition time of resource; What resource mark was set deposits the stack time threshold, obtains according to the acquisition time of current detection time and resource and deposits the stack time, deposits the stack time and the described stack time threshold of depositing detects whether the task deadlock takes place by more described.Compared with prior art, the present invention detects the method for deadlock can in time find the task deadlock, has improved the reliability of software.
Again on the one hand, embodiments of the invention provide a kind of method and apparatus of removing deadlock, and the deadlock situation that this method occurs in can removing program improves the reliability of software.
The method that embodiments of the invention are removed deadlock is by the following technical solutions:
A kind of method of removing deadlock comprises:
Stop task run;
Determine the position of the resource mark of generation deadlock, as deadlock position;
With the resource mark more than the deadlock position, from stack, eject and preserve;
The resource mark that deadlock takes place is ejected, and discharge the resource of this generation deadlock;
The resource mark of preserving is pushed back stack.
The device that embodiments of the invention are removed deadlock is by the following technical solutions:
A kind of device of removing deadlock comprises:
The task stopping modular is used for stopping task run when detecting task generation deadlock;
The deadlock position determination module is used for definite position that the resource mark of deadlock takes place after described task stopping modular stops task run, as deadlock position;
The second resource mark pop-up module, the resource mark more than the deadlock position that is used for described deadlock position determination module is determined ejects from stack and preserves;
The resource release module is used for after the described second resource mark pop-up module is finished ejection and preserved operation, and the resource mark of the generation deadlock that described deadlock position determination module is definite ejects, and discharges the resource of this generation deadlock;
Resource mark pushes back module, is used for after described resource release module discharges the resource of deadlock the resource mark of preserving being pushed back stack.
Embodiments of the invention are removed the method and apparatus of deadlock, behind the generation task deadlock, at first stop the operation of task, determine the position of the resource mark of generation deadlock, as deadlock position; Then, the resource mark more than the deadlock position is ejected from stack and preserves; Then, the resource mark that deadlock takes place is ejected, and discharge the resource of this generation deadlock; At last, the resource mark of preserving is pushed back stack.Compared with prior art, the method that the present invention removes deadlock can stop the operation of task after the task deadlock takes place, the resource that deadlock takes place is discharged step by step, has avoided the further deterioration of software operation state, has improved the reliability of software.
Again on the one hand, embodiments of the invention provide a kind of system that detects and remove deadlock, can detect and the releasing program in the deadlock situation that occurs, improve the reliability of software.
The system that embodiments of the invention detected and removed deadlock is by the following technical solutions:
A kind of system that detects and remove deadlock comprises:
The Deadlock Detection device is used to detect the task deadlock;
The deadlock decontrol is used for after described Deadlock Detection module detects the task deadlock, removes the task deadlock.
Embodiments of the invention detect and remove the system of deadlock, can the deadlock situation that task takes place be detected, after detecting the task deadlock, stop the operation of task, the resource that deadlock takes place is discharged step by step, avoid the further deterioration of software operation state, improved the reliability of software.
Description of drawings
In order to be illustrated more clearly in the embodiment of the invention or technical scheme of the prior art, to do to introduce simply to the accompanying drawing of required use in embodiment or the description of the Prior Art below, apparently, accompanying drawing in describing below only is some embodiments of the present invention, for those of ordinary skills, under the prerequisite of not paying creative work, can also obtain other accompanying drawing according to these accompanying drawings.
The method flow diagram of the detection deadlock that Fig. 1 provides for the embodiment of the invention;
Fig. 2 is method embodiment one process flow diagram of detection deadlock provided by the invention;
The apparatus structure synoptic diagram of the detection deadlock that Fig. 3 provides for the embodiment of the invention;
The method flow diagram of the detection deadlock that Fig. 4 provides for the embodiment of the invention;
Fig. 5 is method embodiment two process flow diagrams of detection deadlock provided by the invention;
The apparatus structure synoptic diagram of the detection deadlock that Fig. 6 provides for the embodiment of the invention;
The method flow diagram of the releasing deadlock that Fig. 7 provides for the embodiment of the invention;
Fig. 8 is method embodiment three process flow diagrams of releasing deadlock provided by the invention;
The apparatus structure synoptic diagram of the releasing deadlock that Fig. 9 provides for the embodiment of the invention;
The detection that Figure 10 provides for the embodiment of the invention and remove the system architecture synoptic diagram of deadlock.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the invention, the technical scheme in the embodiment of the invention is clearly and completely described, obviously, described embodiment only is the present invention's part embodiment, rather than whole embodiment.Based on the embodiment among the present invention, those of ordinary skills belong to the scope of protection of the invention not making the every other embodiment that is obtained under the creative work prerequisite.
Embodiments of the invention provide a kind of methods, devices and systems that detect and remove deadlock.
Below in conjunction with drawings and Examples the present invention is elaborated.
Embodiments of the invention provide a kind of method that detects deadlock, and this method can detect the deadlock situation that occurs in the program, improve the reliability of software.
As shown in Figure 1, described method comprises:
S101: for task is provided with stack;
S102: the resource mark of the resource that described task obtained is pressed into stack successively;
S103: when described task discharges described resource, the described resource mark that is pressed into stack is ejected from stack;
S104: whether the resource mark of the resource that more described task discharges is consistent with the described resource mark that ejects from stack, if inconsistent, then judge deadlock takes place.
Embodiments of the invention detect the method for deadlock, for task is provided with stack, when task is obtained resource, the resource mark of resources available is pressed into stack successively, when task discharges resource, resource mark is ejected from stack, and whether whether consistent the detection task deadlock takes place the resource mark by relatively discharging resource with the described resource mark that ejects from stack.Compared with prior art, the present invention detects the method for deadlock can in time find the task deadlock when task discharges resource, improved the reliability of software.
Provide the method specific embodiment one that the present invention detects deadlock below:
With two parallel tasks 1 in the software and task 2 is example, and as shown in Figure 2, the method for described detection deadlock specifically comprises:
S201: for task 1 and task 2 respectively are provided with a stack, task 1 is obtained resource A and resource B, and task 2 is obtained resource C and resource D, and the resource mark of resource A, B, C, D is respectively a, b, c, d;
Wherein, corresponding with task 1 is stack 1, and corresponding with task 2 is stack 2.Described stack is used for the resource mark of store tasks resources available, and each resource has the resource mark of this resource of unique identification.
Wherein, the time order and function that obtains described four resources is in proper order: resource A, resource B, resource C and resource D.There is relation one to one in the resource mark of each resource and described resource, and in the present embodiment, the resource mark of described resource A, resource B, resource C, resource D is respectively a, b, c, d.In other embodiments, the resource mark of resource A, resource B, resource C, resource D can identify with other letter or number.
S202: resource mark a, b, c, d are pressed into stack successively;
Wherein, described resource mark comprises the address of resource in internal memory and the acquisition time of resource, and the resource mark that different resource is corresponding different can be learnt the resource mark of this resource by the title of resource, also i.e. address and the acquisition time of this resource in internal memory.According to the sequencing that obtains resource among the step S201,, be pressed into stack 1 successively with the resource mark a of resource A, the resource mark b of resource B; With the resource mark c of resource C, the resource mark d of resource D, be pressed into stack 2 successively.
S203: when task discharges resource X, from the stack resource mark x that is hit by a bullet out;
When task discharges resource, from stack, eject a resource mark x, wherein x may be among a, b, c, the d any.Wherein, the order that described resource mark ejects stack can be provided with, can be identical with the order that is pressed into stack, also can with the reversed in order that is pressed into stack.In the present embodiment, the resource mark order that ejects stack is set to and is pressed into the reversed in order of stack.
That is: the order of resource mark ejection stack is: resource mark d, resource mark c, resource mark b, resource mark a.
S204: whether the resource mark of the resource X that more described task discharges is consistent with the described resource mark x that ejects from stack, if inconsistent, then judge deadlock takes place.
Because there are relation one to one in resource and resource mark, when discharging resource, as long as know the title of the resource that is discharged, can learn the resource mark of this resource.For example, when the resource that discharges is resource A, can learn that by the title A of this resource the resource mark of this resource A is resource mark a.
Wherein, resource mark ejects the order of stack and fixes, and the order that discharges resource can be at random, for present embodiment, when discharging resource, whether the resource mark that relatively discharges resource X consistent with the resource mark x that ejects from stack, just compare whether discharge the address of resource X in internal memory and acquisition time and the resource mark x that ejects from stack included address and acquisition time consistent.
For example: when the resource that discharges is resource A, from stack, eject a resource mark, because the resource mark of resource A is a, address and acquisition time that address that the resource mark that ejects in the more described stack is included and acquisition time and resource mark a are included, if inconsistent, the task deadlock then takes place.
Thereby, utilize embodiments of the invention to detect the method for deadlock, when task discharges resource, can detect the deadlock situation that occurs in the program, improved the reliability of software.
Corresponding with the method for above-mentioned detection deadlock, embodiments of the invention also provide a kind of device that detects deadlock, and this device can detect the deadlock situation that occurs in the program, improve the reliability of software.
As shown in Figure 3, the device of described detection deadlock comprises: stack is provided with module 301, resource mark is pressed into module 302, the first resource mark pop-up module 303 and first comparison module 304.
In the present embodiment, stack is provided with module 301 and is used to task that stack is set; Resource mark is pressed into module 302 and is used for after described stack is provided with module 301 and for task stack is set, and the resource mark of the resource that described task obtained is pressed into stack successively; The first resource mark pop-up module 303 is used for when described task discharges described resource, described resource mark is pressed into the described resource mark that module 302 is pressed in the stack ejects from stack; First comparison module 304 is used for when the described first resource mark module 303 ejects resource mark, and whether the resource mark of the resource that more described task discharges is consistent with the described resource mark that ejects from stack.
Embodiments of the invention detect the device of deadlock, stack is provided with module 301 and for task stack is set, when task is obtained resource, resource mark is pressed into module 302 resource mark of resources available is pressed into stack successively, when task discharges resource, the first resource mark pop-up module 303 ejects resource mark from stack, whether first comparison module 304 is consistent with the described resource mark that ejects from stack by the resource mark that relatively discharges resource, detects whether the task deadlock takes place.Compared with prior art, the present invention detects the device of deadlock can in time find the task deadlock when task discharges resource, improved the reliability of software.
As shown in Figure 3, the device of described detection deadlock also comprises first judge module 305, is used for the comparative result according to described first comparison module 304, judges whether to take place deadlock, resource mark and the described resource mark that ejects from stack as if discharge resource are inconsistent, then judge deadlock takes place.
For the device of present embodiment detection deadlock, the order that described resource mark ejects stack is identical with the order that is pressed into stack or opposite; Described resource mark comprises the acquisition time of resource addresses and resource, the resource mark that different resources is corresponding different.
Described first comparison module 305, whether consistent by relatively discharging the address and the acquisition time that comprise in resource addresses and acquisition time and the resource mark that from stack, ejects, come the resource mark of resource of more described task release whether consistent with the described resource mark that from stack, ejects.
Thereby, utilize embodiments of the invention to detect the device of deadlock, can detect the deadlock situation that occurs in the program, improve the reliability of software.
Embodiments of the invention provide another to detect the method for deadlock, and this method can detect the deadlock situation that occurs in the program, improve the reliability of software.
As shown in Figure 4, described method comprises:
S401: for task is provided with stack;
S402: the resource mark of the resource that described task obtained is pressed into stack, and described resource mark comprises the acquisition time of resource;
S403: what resource mark was set deposits the stack time threshold;
S404: obtain according to the acquisition time of current detection time and resource and to deposit the stack time;
S405: deposit the stack time and compare described,, then judge deadlock takes place if deposit the stack time greater than depositing the stack time threshold with the described stack time threshold of depositing.
Embodiments of the invention detect the method for deadlock, for task is provided with stack, when task is obtained resource, the resource mark of resources available are pressed into stack, and described resource mark comprises the acquisition time of resource; What resource mark was set deposits the stack time threshold, obtains according to the acquisition time of current detection time and resource and deposits the stack time, deposits the stack time and the described stack time threshold of depositing detects whether the task deadlock takes place by more described.Compared with prior art, the present invention detects the method for deadlock can in time find the task deadlock, has improved the reliability of software.
Provide the method specific embodiment two that the present invention detects deadlock below:
With two parallel tasks 3 in the software and task 4 is example, and as shown in Figure 5, the method for described detection deadlock specifically comprises:
S501: for task 3 and task 4 respectively are provided with a stack, task 3 is obtained resource P and resource Q, and task 4 is obtained resource U and resource V, and the resource mark of resource P, Q, U, V is respectively p, q, u, v;
Wherein, corresponding with task 3 is stack 3, and corresponding with task 4 is stack 4.Described stack is used for the resource mark of store tasks resources available.
Wherein, the time order and function that obtains described four resources is in proper order: resource P, resource Q, resource U and resource V.There is relation one to one in the resource mark of each resource and described resource, and in the present embodiment, the resource mark of described resource P, resource Q, resource U, resource V is respectively p, q, u, v.In other embodiments, the resource mark of resource P, resource Q, resource U, resource V can identify with other letter or number.
S502: resource mark p, q, u, v are pressed into stack successively;
Wherein, described resource mark comprises the address of resource in internal memory and the acquisition time of resource, the resource mark that different resources is corresponding different.According to the sequencing that obtains resource among the step S501, the acquisition time of resource P and resource Q is pressed into stack 3 successively as a marks packets respectively, the acquisition time of resource U and resource V is pressed into stack 4 successively as a marks packets respectively.Mark q with resource mark p, the resource Q of resource P is pressed into stack 3 successively; With the resource mark u of resource U, the resource mark v of resource V, be pressed into stack 4 successively.
S503: what resource mark p, q, u, v were set deposits stack time threshold T0;
For each resource mark, there is a maximum critical value residence time in stack.When the task deadlock did not take place, the time that resource mark stops in stack will eject from stack before reaching this critical value.Deposit stack time threshold T0 with what this critical value was made as resource mark, each resource mark deposit stack time threshold T0 difference.
S504: compared with the acquisition time of resource current detection time, draw both time differences, be and deposit the stack time T;
S505: the described stack time T of depositing is compared with described time threshold T0,, then judge deadlock takes place if deposit the stack time T greater than time threshold T0.
The stack time T of depositing of described resource mark is compared with described time threshold T0, if deposit the stack time T greater than described time threshold T0, then explanation has resource to can not get for a long time discharging, and the resource mark of this resource correspondence is deposited in stack for a long time, and the task deadlock has taken place.
For the method for above-mentioned detection deadlock, when task is only obtained a resource, can use described method to carry out the detection of deadlock equally.
Thereby, utilize embodiments of the invention to detect the method for deadlock, can detect the deadlock situation that occurs in the program, improve the reliability of software.
Corresponding with the method for above-mentioned detection deadlock, embodiments of the invention also provide a kind of device that detects deadlock, and this device can detect the deadlock situation that occurs in the program, improve the reliability of software.
As shown in Figure 6, the device of described detection deadlock comprises: stack is provided with module 601, and resource mark is pressed into module 602, and time threshold is provided with module 603, deposits the stack time-obtaining module 604 and second comparison module 605.
In the present embodiment, stack is provided with module 601 and is used to task that stack is set; Resource mark is pressed into module 602 and is used for after stack is provided with module 601 and for task stack is set, and the resource mark of the resource that described task obtained is pressed into stack, and described resource mark comprises the acquisition time of resource; What time threshold was provided with that module 603 is used to be provided with resource mark deposits the stack time threshold; Depositing stack time-obtaining module 604 is used for being pressed into the acquisition time of the resource in the resource mark that module 602 is pressed into stack and obtaining current detection time and deposit the stack time according to described resource mark; Second comparison module 605 is used for described stack time of depositing that stack time-obtaining module 604 obtains and the described time threshold deposited is provided with the stack time threshold of depositing that module 603 is provided with and compares.
Embodiments of the invention detect the device of deadlock, and stack is provided with module 601 for task is provided with stack, and when task was obtained resource, resource mark was pressed into module 602 resource mark of resources available is pressed into stack successively, and described resource mark comprises the acquisition time of resource; What time threshold was provided with that module 603 is provided with resource mark deposits the stack time threshold, depositing stack time-obtaining module 604 obtains according to the acquisition time of current detection time and resource and deposits the stack time,, detect whether the task deadlock takes place by more described stack time and the described stack time threshold of depositing deposited by second comparison module 605.Compared with prior art, the present invention detects the device of deadlock can in time find the task deadlock, has improved the reliability of software.
Wherein, the described stack time-obtaining module 604 of depositing by compared with the acquisition time of resource current detection time, draws both time differences, is described depositing the stack time.
As shown in Figure 6, the device of described detection deadlock also comprises second judge module 606, is used for the comparative result according to described second comparison module 605, judges whether to take place deadlock, deposits the stack time greater than the described stack time threshold of depositing as if described, then judges deadlock takes place.
Thereby, utilize embodiments of the invention to detect the device of deadlock, can detect the deadlock situation that occurs in the program, improve the reliability of software.
Embodiments of the invention also provide a kind of method of removing deadlock, and the deadlock situation that this method occurs in can removing program improves the reliability of software.
As shown in Figure 7, described method comprises:
S701: stop task run;
S702: determine the position of the resource mark of generation deadlock, as deadlock position;
S703:, from stack, eject and preserve with the resource mark more than the deadlock position;
S704: the resource mark that deadlock will take place ejects, and discharges the resource of this generation deadlock;
S705: the resource mark of preserving is pushed back stack.
Embodiments of the invention are removed the method for deadlock, behind the generation task deadlock, at first stop the operation of task, determine the position of the resource mark of generation deadlock, as deadlock position; Then, the resource mark more than the deadlock position is ejected from stack and preserves; Then, the resource mark that deadlock takes place is ejected, and discharge the resource of this generation deadlock; At last, the resource mark of preserving is pushed back stack.Compared with prior art, the method that the present invention removes deadlock can stop the operation of task after the task deadlock takes place, the resource that deadlock takes place is discharged step by step, has avoided the further deterioration of software operation state, has improved the reliability of software.
Wherein, the method for described releasing deadlock can be carried out after detecting deadlock, also can carry out the detection of deadlock, directly carries out behind the generation deadlock.
Provide the method specific embodiment three that the present invention detects deadlock below:
As shown in Figure 8, detect at first whether the task deadlock takes place, if detect the task deadlock, then described method specifically comprises the steps:
S801: stop task run;
In order to allow the task recovery operation that deadlock takes place, just need to remove deadlock, just long-term occupied resource is discharged.Because in the concurrent environment of complexity, the operation of multitask might cause confusion, discharging resource in addition need adjust stack, can not be interrupted in the process of adjusting.Therefore, need allow all tasks out of service, just can discharge the work of resource and adjustment stack.
In order to achieve the above object, introduce a secure resources.The home of described secure resources in each task placed, and this home is certain fixed position in the task, does not have other resources to be acquired at this home.During operate as normal, described secure resources is obtained the back by each task and just discharges immediately, can not influence the operate as normal of task.
When monitor task detects deadlock, just apply for this secure resources, and wait for a period of time that when other tasks were carried out this home, application will be out of service less than this secure resources.
S802: determine the position of the resource mark of generation deadlock, as deadlock position;
After detecting task generation deadlock, find out the position that the resource mark of deadlock takes place in the stack, and this position is made as deadlock position.
S803:, from stack, eject and preserve with the resource mark more than the deadlock position;
The resource mark that described deadlock position is above does not comprise the resource mark that deadlock takes place.
S804: the resource mark that deadlock will take place ejects, and discharges the resource of this generation deadlock;
S805: the resource mark of preserving is pushed back stack;
The resource mark of preserving among the step S803 is pushed back in the stack again according to former order.
S806: recovery tasks operation.
Monitor task discharges safety lock, other task recovery operations.
If still detect after the task recovery operation task deadlock is arranged, repeating step S801-S806 then is until there not being the task deadlock to take place.
Wherein, for above-mentioned two kinds of detected deadlocks of method that detect deadlock, the method that the present invention removes deadlock all is suitable for.
Thereby, utilize embodiments of the invention to remove the method for deadlock, the deadlock situation that occurs in can removing program improves the reliability of software.
Corresponding with the method for above-mentioned releasing deadlock, embodiments of the invention also provide a kind of device of removing deadlock, and the deadlock situation that this device occurs in can removing program improves the reliability of software.
As shown in Figure 9, the device of described releasing deadlock comprises that task stopping modular 901, deadlock position determination module 902, the second resource mark pop-up module 903, resource release module 904 and resource mark push back module 905.
In the present embodiment, task stopping modular 901 is used for stopping task run when detecting task generation deadlock; Deadlock position determination module 902 is used for definite position that the resource mark of deadlock takes place after described task stopping modular 901 stops task run, as deadlock position; Resource mark more than the deadlock position that the second resource mark pop-up module 903 is used for described deadlock position determination module 902 is determined ejects from stack and preserves; Resource release module 904 be used for when the described second resource mark pop-up module 903 finish eject and preserve operation after, the resource mark of the generation deadlock that described deadlock position determination module 902 is determined ejects, and discharges the resource of this generation deadlock; Resource mark pushes back module 905 and is used for after described resource release module 904 discharges the resource of deadlock the resource mark of preserving being pushed back stack.
Embodiments of the invention are removed the device of deadlock, behind the generation task deadlock, task stopping modular 901 stops the operation of task, deadlock position determination module 902 is determined the position of the resource mark of generation deadlock, as deadlock position, the second resource mark pop-up module 903 ejects the resource mark more than the deadlock position and preserves from stack, the resource mark that deadlock will take place resource release module 904 ejects, and discharging the resource of this generation deadlock, resource mark pushes back module 905 resource mark of preserving is pushed back stack.Compared with prior art, the device that the present invention removes deadlock can stop the operation of task after the task deadlock takes place, the resource that deadlock takes place is discharged step by step, has avoided the further deterioration of software operation state, has improved the reliability of software.
As shown in Figure 9, described device also comprises task recovery module 906, is used for after described resource mark pushes back module 905 resource mark of preserving is pushed back stack the recovery tasks operation.
Thereby, utilize embodiments of the invention to remove the device of deadlock, the deadlock situation that occurs in can removing program improves the reliability of software.
Embodiments of the invention also provide a kind of system that detects and remove deadlock, and the deadlock situation that this system occurs in can removing program improves the reliability of software.
As shown in figure 10, described system comprises:
Deadlock Detection device 1001 is used to detect the task deadlock;
Deadlock decontrol 1002 is used for after described Deadlock Detection device 1001 detects the task deadlock, removes the task deadlock.
Embodiments of the invention detect and remove the system of deadlock, can the deadlock situation that task takes place be detected, after detecting the task deadlock, stop the operation of task, the resource that deadlock takes place is discharged step by step, avoid the further deterioration of software operation state, improved the reliability of software.
One of ordinary skill in the art will appreciate that all or part of flow process that realizes in the foregoing description method, be to instruct relevant hardware to finish by computer program, described program can be stored in the computer read/write memory medium, this program can comprise the flow process as the embodiment of above-mentioned each side method when carrying out.Wherein, described storage medium can be magnetic disc, CD, read-only storage memory body (Read-Only Memory, ROM) or at random store memory body (Random Access Memory, RAM) etc.
The above; it only is the embodiment of the embodiment of the invention; but the protection domain of the embodiment of the invention is not limited thereto; anyly be familiar with those skilled in the art in the technical scope that the present invention discloses; the variation that can expect easily or replacement all should be encompassed within protection scope of the present invention.Therefore, the protection domain of the embodiment of the invention should be as the criterion with the protection domain of claim.

Claims (22)

1, a kind of method that detects deadlock is characterized in that, comprising:
For task is provided with stack;
The resource mark of the resource that described task obtained is pressed into stack successively;
When described task discharges described resource, the described resource mark that is pressed in the stack is ejected from stack;
Whether the resource mark of the resource that more described task discharges is consistent with the described resource mark that ejects from stack, if inconsistent, then judge deadlock takes place.
2, the method for detection deadlock according to claim 1 is characterized in that, the order that described resource mark ejects stack is identical with the order that is pressed into stack or opposite.
3, the method for detection deadlock according to claim 2 is characterized in that, described resource mark comprises the acquisition time of resource addresses and resource.
4, the method for detection deadlock according to claim 3 is characterized in that, whether consistent step comprises for the resource mark of the resource that described task discharges and the described resource mark that ejects from stack:
Whether the address and the acquisition time that comprise in the resource addresses that more described task discharges and acquisition time and the resource mark that ejects from stack be consistent.
5, a kind of device that detects deadlock is characterized in that, comprising:
Stack is provided with module, is used to task that stack is set;
Resource mark is pressed into module, and being used for when described stack is provided with module is after task is provided with stack, and the resource mark of the resource that described task obtained is pressed into stack successively;
The first resource mark pop-up module is used for when described task discharges described resource, described resource mark is pressed into the described resource mark that module is pressed in the stack ejects from stack;
First comparison module is used for when the described first resource mark module ejects resource mark, and whether the resource mark of the resource that more described task discharges is consistent with the described resource mark that ejects from stack.
6, the device of detection deadlock according to claim 5 is characterized in that, also comprises:
First judge module is used for the comparative result according to described first comparison module, judges whether to take place deadlock, if the resource mark and the described resource mark that ejects from stack of the resource that described task discharges are inconsistent, then judge deadlock takes place.
7, the device of detection deadlock according to claim 5 is characterized in that, the order that described resource mark ejects stack is identical with the order that is pressed into stack or opposite.
8, the device of detection deadlock according to claim 7 is characterized in that, described resource mark comprises the acquisition time of resource addresses and resource.
9, the device of detection deadlock according to claim 7, it is characterized in that, described first comparison module, whether whether the address and the acquisition time that comprise in the resource addresses that discharges by more described task and acquisition time and the resource mark that ejects from stack be consistent, come the resource mark of resource of more described task release consistent with the described resource mark that ejects from stack.
10, a kind of method that detects deadlock is characterized in that, comprising:
For task is provided with stack;
The resource mark of the resource that described task obtained is pressed into stack, and described resource mark comprises the acquisition time of resource;
What described resource mark was set deposits the stack time threshold;
Obtain according to the acquisition time of current detection time and resource and to deposit the stack time;
Deposit the stack time and compare described,, then judge deadlock takes place if deposit the stack time greater than depositing the stack time threshold with the described stack time threshold of depositing.
11, the method for detection deadlock according to claim 10 is characterized in that, obtains the step of depositing the stack time according to the acquisition time of current detection time and resource and comprises:
Compared with the acquisition time of resource current detection time, draw both time differences, be described depositing the stack time.
12, a kind of device that detects deadlock is characterized in that, comprising:
Stack is provided with module, is used to task that stack is set;
Resource mark is pressed into module, and being used for when stack is provided with module is after task is provided with stack, and the resource mark of the resource that described task obtained is pressed into stack, and described resource mark comprises the acquisition time of resource;
Time threshold is provided with module, and what be used to be provided with resource mark deposits the stack time threshold;
Deposit the stack time-obtaining module, be used for being pressed into the acquisition time of the resource in the resource mark that module is pressed into stack and obtaining current detection time and deposit the stack time according to described resource mark;
Second comparison module is used for depositing the stack time of depositing that the stack time-obtaining module obtains and comparing with the stack time threshold of depositing that described time threshold is provided with the module setting described.
13, the device of detection deadlock according to claim 12 is characterized in that, also comprises:
Second judge module is used for the comparative result according to described second comparison module, judges whether to take place deadlock, deposits the stack time greater than the described stack time threshold of depositing as if described, then judges deadlock takes place.
14, the device of detection deadlock according to claim 12 is characterized in that, the described stack time-obtaining module of depositing by compared with the acquisition time of resource current detection time, draws both time differences, is described depositing the stack time.
15, a kind of method of removing deadlock is characterized in that, comprising:
Stop task run;
Determine the position of the resource mark of generation deadlock, as deadlock position;
With the resource mark more than the deadlock position, from stack, eject and preserve;
The resource mark that deadlock takes place is ejected, and discharge the resource of this generation deadlock;
The resource mark of preserving is pushed back stack.
16, the method for releasing deadlock according to claim 15 is characterized in that, after described resource mark with preservation pushes back the step of stack, also comprises:
The recovery tasks operation.
17, a kind of device of removing deadlock is characterized in that, comprising:
The task stopping modular is used for stopping task run when detecting task generation deadlock;
The deadlock position determination module is used for definite position that the resource mark of deadlock takes place after described task stopping modular stops task run, as deadlock position;
The second resource mark pop-up module, the resource mark more than the deadlock position that is used for described deadlock position determination module is determined ejects from stack and preserves;
The resource release module is used for after the described second resource mark pop-up module is finished ejection and preserved operation, and the resource mark of the generation deadlock that described deadlock position determination module is definite ejects, and discharges the resource of this generation deadlock;
Resource mark pushes back module, is used for after described resource release module discharges the resource of deadlock the resource mark of preserving being pushed back stack.
18, the device of releasing deadlock according to claim 17 is characterized in that, also comprises:
The task recovery module is used for after described resource mark pushes back module the resource mark of preserving is pushed back stack the recovery tasks operation.
19, a kind of system that detects and remove deadlock is characterized in that, comprising:
The Deadlock Detection device is used to detect the task deadlock;
The deadlock decontrol is used for after described Deadlock Detection device detects the task deadlock, removes the task deadlock.
20, the system of detection according to claim 19 and releasing deadlock is characterized in that described Deadlock Detection device comprises:
Stack is provided with module, is used to task that stack is set;
Resource mark is pressed into module, and being used for when described stack is provided with module is after task is provided with stack, and the resource mark of the resource that described task obtained is pressed into stack successively;
The first resource mark pop-up module is used for when described task discharges described resource, described resource mark is pressed into the described resource mark that module is pressed in the stack ejects from stack;
First comparison module is used for when the described first resource mark module ejects resource mark, and whether the resource mark of the resource that more described task discharges is consistent with the described resource mark that ejects from stack;
First judge module is used for the comparative result according to described first comparison module, judges whether to take place deadlock, if the resource mark and the described resource mark that ejects from stack of the resource that described task discharges are inconsistent, then judge deadlock takes place.
21, the system of detection according to claim 20 and releasing deadlock is characterized in that described resource mark comprises the acquisition time of resource addresses and resource.
22, the system of detection according to claim 21 and releasing deadlock is characterized in that described Deadlock Detection device also comprises:
Time threshold is provided with module, and what be used to be provided with resource mark deposits the stack time threshold;
Deposit the stack time-obtaining module, be used for being pressed into the acquisition time of the resource in the resource mark that module is pressed into stack and obtaining current detection time and deposit the stack time according to described resource mark;
Second comparison module is used for depositing the stack time of depositing that the stack time-obtaining module obtains and comparing with the stack time threshold of depositing that described time threshold is provided with the module setting described;
Second judge module is used for the comparative result according to described second comparison module, judges whether to take place deadlock, deposits the stack time greater than the described stack time threshold of depositing as if described, then judges deadlock takes place.
CN2008101115384A 2008-06-05 2008-06-05 Method, device and system for detecting and removing deadlock Expired - Fee Related CN101295266B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2008101115384A CN101295266B (en) 2008-06-05 2008-06-05 Method, device and system for detecting and removing deadlock

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2008101115384A CN101295266B (en) 2008-06-05 2008-06-05 Method, device and system for detecting and removing deadlock

Publications (2)

Publication Number Publication Date
CN101295266A true CN101295266A (en) 2008-10-29
CN101295266B CN101295266B (en) 2010-06-16

Family

ID=40065563

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2008101115384A Expired - Fee Related CN101295266B (en) 2008-06-05 2008-06-05 Method, device and system for detecting and removing deadlock

Country Status (1)

Country Link
CN (1) CN101295266B (en)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101576830B (en) * 2009-06-04 2011-11-30 中兴通讯股份有限公司 Deadlock detection method and device of database transaction lock mechanism
CN103279417A (en) * 2013-06-05 2013-09-04 福州瑞芯微电子有限公司 Methods and device for detecting abnormal locking
CN104239147A (en) * 2014-10-20 2014-12-24 浪潮(北京)电子信息产业有限公司 Method and system for processing deadlock cycle
CN105700851A (en) * 2016-01-08 2016-06-22 大唐微电子技术有限公司 Method and device for implementing push and pop
CN107305507A (en) * 2016-04-25 2017-10-31 北京京东尚科信息技术有限公司 Deadlock control method and device
CN110427272A (en) * 2019-07-26 2019-11-08 新华三技术有限公司成都分公司 Interface function localization method, device and the network equipment
CN112256442A (en) * 2019-07-22 2021-01-22 中兴通讯股份有限公司 Database deadlock detection method and device
CN112994990A (en) * 2021-05-20 2021-06-18 蚂蚁金服(杭州)网络技术有限公司 Loop detection method and device, electronic equipment and storage medium
CN113703987A (en) * 2021-09-14 2021-11-26 中国银行股份有限公司 Java task deadlock detection method and device

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7093262B2 (en) * 2002-07-30 2006-08-15 Intel Corporation Detecting deadlocks in multithreaded programs
US20070150897A1 (en) * 2005-12-22 2007-06-28 International Business Machines Corporation Methods and apparatus for detecting deadlock in multithreading programs
CN1811719A (en) * 2006-02-22 2006-08-02 福建师范大学 Method for detecting and intervening deadlock of single-threading microprocessor
US8141087B2 (en) * 2006-03-31 2012-03-20 International Business Machines Corporation Resolving computing resource deadlocks based on priority and dependent processes

Cited By (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101576830B (en) * 2009-06-04 2011-11-30 中兴通讯股份有限公司 Deadlock detection method and device of database transaction lock mechanism
CN103279417A (en) * 2013-06-05 2013-09-04 福州瑞芯微电子有限公司 Methods and device for detecting abnormal locking
CN104239147B (en) * 2014-10-20 2018-03-09 浪潮(北京)电子信息产业有限公司 One kind processing deadlock round-robin method and system
CN104239147A (en) * 2014-10-20 2014-12-24 浪潮(北京)电子信息产业有限公司 Method and system for processing deadlock cycle
CN105700851B (en) * 2016-01-08 2018-06-01 大唐微电子技术有限公司 A kind of method and apparatus realized pop down and play stack
CN105700851A (en) * 2016-01-08 2016-06-22 大唐微电子技术有限公司 Method and device for implementing push and pop
CN107305507A (en) * 2016-04-25 2017-10-31 北京京东尚科信息技术有限公司 Deadlock control method and device
CN107305507B (en) * 2016-04-25 2020-05-01 北京京东尚科信息技术有限公司 Deadlock control method and device
CN112256442A (en) * 2019-07-22 2021-01-22 中兴通讯股份有限公司 Database deadlock detection method and device
CN110427272A (en) * 2019-07-26 2019-11-08 新华三技术有限公司成都分公司 Interface function localization method, device and the network equipment
CN110427272B (en) * 2019-07-26 2022-07-01 新华三技术有限公司成都分公司 Interface function positioning method and device and network equipment
CN112994990A (en) * 2021-05-20 2021-06-18 蚂蚁金服(杭州)网络技术有限公司 Loop detection method and device, electronic equipment and storage medium
CN112994990B (en) * 2021-05-20 2021-07-30 蚂蚁金服(杭州)网络技术有限公司 Loop detection method and device, electronic equipment and storage medium
CN113703987A (en) * 2021-09-14 2021-11-26 中国银行股份有限公司 Java task deadlock detection method and device
CN113703987B (en) * 2021-09-14 2024-02-23 中国银行股份有限公司 Java task deadlock detection method and device

Also Published As

Publication number Publication date
CN101295266B (en) 2010-06-16

Similar Documents

Publication Publication Date Title
CN101295266B (en) Method, device and system for detecting and removing deadlock
CN103259688B (en) A kind of method for diagnosing faults of distributed memory system and device
EP3674906B1 (en) Connector, nvme storage device and computer device
CN103839007B (en) A kind of method and system detecting abnormal thread
CN104520868B (en) For detecting the system that allocating stack is distorted
CN107239238B (en) Storage IO operation method and device based on distributed lock
CN103279406A (en) Method and device for isolating internal memories
CN103618744A (en) Intrusion detection method based on fast k-nearest neighbor (KNN) algorithm
JP2008035269A5 (en)
CN109144754A (en) A kind of method for testing reliability and device
US8751873B2 (en) Proactively removing channel paths in error from a variable scope of I/O devices
CN104932830B (en) Information processing method and electronic equipment
CN105389161B (en) Collision detection method, transactional memory system and the microprocessor of transaction internal memory
CN107430536A (en) The technology identified for the basic reason that memory damage leak is used after release
CN109061585A (en) A kind of radar data storage method and device
EP3859528A3 (en) Method and apparatus for handling memory failure, electronic device and storage medium
CN105786680B (en) Memory pre-analysis methods and its system after Kernel Panic
JP3222083B2 (en) Shared memory controller
CN106599236A (en) Metadata storage method and apparatus for file system
CN102436405A (en) Saving method and device as well as tempering detection method and device for process context
CN105138429B (en) A kind of Copy on write Snapshot Method and system
CN103744742A (en) Method for restoring bad block of internal memory
EP3706026B1 (en) Fraudulent transmission data detection device, fraudulent transmission data detection method, and storage medium
CN104536845B (en) The method of data synchronization and device of write buffer
CN105721342B (en) The method for connecting network and system of multi-process equipment

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
ASS Succession or assignment of patent right

Owner name: CHENGDU CITY HUAWEI SAIMENTEKE SCIENCE CO., LTD.

Free format text: FORMER OWNER: HUAWEI TECHNOLOGY CO., LTD.

Effective date: 20090424

C41 Transfer of patent application or patent right or utility model
TA01 Transfer of patent application right

Effective date of registration: 20090424

Address after: Qingshui River District, Chengdu high tech Zone, Sichuan Province, China: 611731

Applicant after: Chengdu Huawei Symantec Technologies Co., Ltd.

Address before: Headquarters office building, Bantian HUAWEI base, Longgang District, Guangdong, Shenzhen Province, China: 518129

Applicant before: Huawei Technologies Co., Ltd.

C14 Grant of patent or utility model
GR01 Patent grant
C56 Change in the name or address of the patentee

Owner name: HUAWEI DIGITAL TECHNOLOGY (CHENGDU) CO., LTD.

Free format text: FORMER NAME: CHENGDU HUAWEI SYMANTEC TECHNOLOGIES CO., LTD.

CP01 Change in the name or title of a patent holder

Address after: 611731 Chengdu high tech Zone, Sichuan, West Park, Qingshui River

Patentee after: Huawei Symantec Technologies Co., Ltd.

Address before: 611731 Chengdu high tech Zone, Sichuan, West Park, Qingshui River

Patentee before: Chengdu Huawei Symantec Technologies Co., Ltd.

CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20100616

Termination date: 20180605