Atitit. Thread deadlock run-fly detection with auto-unlock with manual unlock Java C #. NET PHP JavaScript.

Source: Internet
Author: User

Atitit. Thread deadlock run-fly detection with auto-unlock with manual unlock java C #. NET PHP JavaScript.

1. Phenomenon:: The main program stuck unresponsive, multi-line tasks do not go down 1

2. Reason:: Use jv jprofile View Thread, the original two threads deadlock. 1

3. Java Disadvantage, default cannot automatically unlock deadlock 1

4. Auto Detect and Unlock:: Using watchdog watchdog 2

4.1. Deadlock detection algorithm (too cumbersome, not recommended) 2

4.2. Hardware watchdog 2

4.3. Software watchdog implementation --timer 2

4.4. LINUX watchdog 2

5. Unlocking the deadlock policy 3

5.1. Program Reset 3

5.2. Revoke the thread and deprive the resource. 3

5.3. Process fallback policy, 3

6. Task Recovery --- transaction redo 3

7. Manually unlock the deadlock 3

8. Watchdog principle and implementation 4

9. Java watchdog design Ideas 4

10. Simple example of a deadlock phenomenon, 5

11. Reference 5

1. Phenomenon:: The main program stuck unresponsive, multi-line tasks do not go down

The program runs and flies, and goes into a dead loop, the normal operation of the program is interrupted, The system is unable to continue to work, causing the entire system to become stuck,

2. Reason:: UseJV JprofileView threads, the original two threads are deadlocked.

3. Java, the default does not automatically unlock the deadlock

Unlike databases, many databases can automatically unlock deadlocks and then schedule transaction redo.

The language level of Java does not have this function, it can only be implemented at the class library level at the same time.

Author :: Old Wow's paw attilax ayron, email:[email protected]

Reprint please indicate source: Http://blog.csdn.net/attilax

4. Automatic detection and release of deadlocks:: Using the watchdogwatchdog

deadlock detection and recovery refers to the system has a special mechanism, when the deadlock occurs, the mechanism can detect the location and cause of the deadlock, and can destroy the necessary conditions of the deadlock through external forces, so that the concurrent process from the deadlock state recovery.

4.1. Deadlock detection algorithm (too cumbersome, not recommended) 4.2. Hardware watchdog

A chip designed to monitor the running state of a program

4.3. Software watchdog implementation--timer4.4. Linuxof thewatchdog

Linux comes with a watchdog implementation that monitors the operation of the system, including a kernel watchdog module and a user-space Watchdog Program. [1]

The kernel watchdog module communicates with the user space by/dev/watchdog this character device. Once the user space program opens the/dev/watchdog device, it causes a 1 -minute timer to be started in the kernel, after which the user-space program needs to be guaranteed to be 1 minutes to the device, each write operation causes the timer to be reset. If the user space program does not write within 1 minutes, the timer expires causing a system reboot operation. [1] 

Guard Dog, also called watchdog timer, is a Timercircuit , usually has an input , called Feed the dog ., during normal work , output a signal to the dog at intervals, give WDT 0 , If the dog is not fed at the specified time ( Usually when the program is running ), the WDT is timed out , giving a Reset Signalto the Reset . Prevent  crashes . The role of the watchdog is to prevent the program from going through a dead loop or running a program.

5. Unlock the deadlock policy 5.1. Program Reset

( 1 The simplest and most common way to do this is to reboot the system, but this approach is expensive, which means that all the computations that have been done before that process are wasted, including those involved in the deadlock, and the processes that are not involved in deadlocks.

5.2. Revoke the thread and deprive the resource.

Terminates the process that participates in the deadlock, reclaims the resources that they occupy, and thus unlocks the deadlock. At this point there are two situations: one-time undo all the processes involved in the deadlock, deprive all resources, or gradually revoke the process involved in the deadlock, gradually recover the resources occupied by the deadlock process. In general, the process of phasing out is chosen in accordance with certain principles, with the aim of undoing the least costly processes, such as determining the cost of the process by the priority of the process, taking into account factors such as the cost of the process runtime and the cost of the external job associated with the process.  

5.3. Process fallback policy,

That is, the process that participates in the deadlock is rolled back to a point where the deadlock did not occur and continues at this point, so that the deadlock does not occur again when it executes again. Although this is a better approach, but the operation of the system overhead, it is necessary to have the stack such a mechanism to record every step of the process changes, so that the future fallback, sometimes this is not possible.

6. Task Recovery---Transaction Redo

A process fallback policy that lets a process that participates in a deadlock fall back to a point where the deadlock did not occur, and continue execution at this point, so that no more deadlocks occur when it executes again. Although this is a better approach, but the operation of the system overhead, to have the stack such a mechanism to record every step of the process changes, so that the future fallback, sometimes it is impossible to do

7. Manual release of Deadlocks

The wrapper system thread , whenever the thread is started , inserts a thread into the thread registration table . when you quit, CLR ...

If the dead lock , the horse CLR, can query , in the manual clr ...

8. Watchdogprinciple andImplement

 Application of watchdog,enables the system to work continuously in unmanned state,its working principle is:One of the watchdog chips and systemsI/OPIN Connection(connected by a variable in pure software),theI/OThe pin is programmed to feed a high level to the watchdog's pin(or Low level,The software is fed into a variable value),This program statement is distributed in the middle of other system control statements, once the system due to interference caused the program to fly into a program segment into the dead loop state,The program that writes the watchdog PIN cannot be executed.,this time,The watchdog circuit will not get a signal from the system.,sends a reset signal to the pin connected to the system reset pin.,Resetting the system,that is, the program starts from the beginning of the program memory.,This enables the automatic reset of the system.

After the system is running, the watchdog counter is activated, the watchdog starts to count automatically, and if it does not clear the watchdog for a certain amount of time, then the watchdog counter will overflow causing the watchdog to break, causing the system to reset. So watch the dog when using a watchdog chip.

Hardware watchdog is the use of a timer to monitor the operation of the main program, that is, during the operation of the main program, we have to reset the timer before the timing time to a dead loop, or that the PC Pointer can not be returned. Then the timing time will reset the system .

The principle of software watchdog technology is similar to this, but it is implemented by software, we stillWuyiSeries, we know that inWuyiThere are two timers in the system, and we can use these two timers to monitor the operation of the main program. We can treatT0set a certain timing time, when the timing of the interruption of the time to assign a variable, and this variable at the beginning of the main program run has an initial value, where we want to set the timing is less than the main program run time, so at the end of the main program to determine the value of the variable, If the value changes as expected, it indicates that theT0The interrupt is normal and resets the program if it has not changed. ForT1we used to monitor the operation of the main program, we gaveT1set a certain timing time, in the main program to reset it, if it can not be reset in a certain time,T1the system will be reset by a timed interrupt. In hereT1the timing time to set more than the main program run time, to the main program to leave a certain amount of headroom. andT1the interruption of the normal or not we again byT0Timer interrupt subroutine to monitor. This makes up a loop,T0MonitoringT1,T1Monitor the main program, and the main program to monitorT0, so as to ensure the stable operation of the system.

9. Javaof thewatchdogDesign Ideas

System software " watchdog " design ideas:

1. Setting of the watchdog timer T0 . Set how T0 works in the initialization block and turn on interrupt (timer event) and Count function.

2. Calculate the time-consuming cycle of the master program. Considering the system function modules and their cycle times, the operating time of the main control program of the system is about. System settings " watchdog " timer T0 timer 60s

3. Each cycle of the master program refreshes the initial value of the T0. If the program enters the " dead Loop " and The initial value of the T0 is not refreshed within 60s, then The watchdog timer T0 will overflow and request an interrupt.

3. design The Interrupt service program for the T0 overflow. This subroutine requires only one instruction, that is, the interrupt vector address (000BH)corresponding to the T0 ( A reference to a thread in JAVA), a write reset, Re-initialize the task and get the correct order of execution

10. Simple example of a deadlock phenomenon,

is there a deadlock in the reference Java? - push cool . htm

11. Reference

Atitit Lifting Database Deadlock processing summary -Attilax 's Column - Blog channel -CSDN.NET.htm

Watchdog_ Baidu Encyclopedia. htm

Java deadlock generation and unlocking -Hijiankang 's Column - Blog channel -CSDN.NET.htm

Atitit. Thread deadlock run-fly detection with auto-unlock with manual unlock Java C #. NET PHP JavaScript.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.