Once you have decided that the implementation will be done using threads, the first task is to logically divide the multiple functionalities in a given system so that
a separate thread could be assigned to perform each individual function.

Name:  Linux Thread models.jpg
Views: 890
Size:  42.5 KB

The Master-Slaves model: Consider an ATM machine system. Here, one thread could be made to manage the touchpadlkeypad, another could manage the displaylbeep functionalities, a third could manage the remote connection with the bank server along with transactions and actual money vending. Now a central manager/master thread will be present to keep all of them synchronised. This is precisely what the 'Master-Slaves model' suggests. The pipeline model: Here the concept is that the first thread runs and produces some outputs based on the system inputs. These intermediate outputs are handed over to the second thread, and so on.

The last thread delivers its output as the system output. Here the previous thread becomes free for the next input as it hands over the output to the next thread in the pipeline. Typically, this model is used in computation intensive applications. The background task model: Consider the case of an operating system at start-up. It generally needs to initiate a DHCP query to acquire the IP address from the network as a part of its boot process. Now this start-up operation cannot wait till the system acquires the IP address and hence could choose to spawn a thread for this activity and proceed ahead with the next start-up sequence. These models are generally used across the industry. The choice of the right model is mostly specific to a given problem and needs proper analysis. The important consideration here is to try and reduce the communication and switching between two threads as much as possible, for better system performance.