# Huang’s Termination detection algorithm

**Huang’s algorithm** is an algorithm for detecting termination in a distributed system. The algorithm was proposed by **Shing-Tsaan Huang** in 1989 in the Journal of Computers.

In a distributed system, a process is either in an active state or in an idle state at any given point of time. Termination occurs when all of the processes becomes idle and there are no any in transit(on its way to be delivered) computational message.

**Assumptions of the algorithm:**

- One of the co-operating processes which monitors the computation is called the
**controlling agent**. - The initial weight of
**controlling agent**is 1 - All other processes are initially idle and have weight 0.
- The computation starts when the controlling agent send a computation message to one of the processes.
- The process become active on receiving a computation message.
- Computation message can be sent only by controlling agent or an active process.
- Control message is sent to controlling agent by an active process when they are becoming idle.
- The algorithm assigns a weight
**W**(such that 0 <**W**< 1 ) to every active process and every in transit message.

**Notations used in the algorithm:**

**B(DW):**Computation message with weight**DW****C(DW)**: Control message with weight**DW**

**Algorithm:**

**Rule to send B(DW) –**- Suppose Process P with weight
**W**is sending**B(DW)**to process Q - Split the weight of the process P into
**W1**and**W2**.

Such thatW = W1 + W2 and W1 > 0, W2 > 0

- Set weight of the process P as
**W1**( i.e**W = W1**) - Send
**B(W2)**to*process Q*, here**DW = W2**. **Note:**Only the Controlling agent or any active process can send Computation message.

- Suppose Process P with weight
**On receiving B(DW) by process Q –**- Add the weight
**DW**to the weight of process Q i.e for process Q,**W = W + DW** - If process Q was idle, it will become active on receiving
**B(DW)**.

- Add the weight
**Rule to send C(DW) –**- Any active process having weight
**W**can become idle by sending**C(W)**to controlling agent - Send a control message
**C(W)**to the controlling agent. Here**DW**=**W**. - Set weight of the process as 0 i.e
**W = 0**. (After this process will become idle.)

- Any active process having weight
**On receiving C(DW) by controlling agent –**- Add the weight received through control message to the weight of controlling agent i.e
**W = W + DW** - After adding, if the weight of controlling agent becomes 1 then it can be conclude that the computation has terminated.

- Add the weight received through control message to the weight of controlling agent i.e

**Advantages of Huang’s Algorithm:**

- The algorithm detects every true termination in finite time.

**Limitations of Huang’s Algorithm:**

- The algorithm is unable to detect computation termination if a message is lost in transit.
- It also does not work when a process fails while in an active state.

## Recommended Posts:

- Deadlock Detection Algorithm in Operating System
- Chandy-Misra-Haas's Distributed Deadlock Detection Algorithm
- Deadlock Detection And Recovery
- Deadlock detection in Distributed systems
- Deadlock Detection in Distributed Systems
- Hierarchical Deadlock Detection in Distributed System
- Program for Banker's Algorithm | Set 1 (Safety Algorithm)
- LRU Approximation (Second Chance Algorithm)
- LOOK Disk Scheduling Algorithm
- C-LOOK Disk Scheduling Algorithm
- Banker's Algorithm in Operating System
- Dekker's algorithm in Process Synchronization
- Bakery Algorithm in Process Synchronization
- Banker's Algorithm in Operating System
- Raymond's tree based algorithm

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.