1
14kviews
What is a thread and advantages of using them? What are different models for organizing threads?

This question appears in Mumbai University > Distributed System

Marks: 10 M

Year: Dec 2015

1 Answer
1
444views

Motivation for Using Threads:

  • The main motivations for using a multithread process instead of multiple single-threaded processes for performing some computation activities are as follows:

  • The overheads involved in creating a ne wprocess are in general considerably greater than those of creating a new thread within a process.

  • Switching between threads sharing the same address space is considerably cheaper than switching between processes that have their own address spaces.

  • Threads allows parallelism to be combined with sequential execution and blocking system calls [Tanenbaum 1995 ].Parallelism improves performance and blocking system calls make programming easier.

  • Resource sharing can be achieved more efficiently and naturally between threads of a process than between processes because all threads of a process share the same address space.

Models for Organizing Threads

  • Depending on an application’s needs, the threads of a process of the application can be organized in different ways. Three commonly used ways to organize the threads of a process are as follows [Tanenbaum 1995] :

  • Dispatcher-Worker Model: We have already seen the use of this model in designing a server process. In this model, the process consists of single dispatcher threads and multiples worker threads. The dispatcher the request to one of the free worker threads for further processing of the request. Each worker threads work on a different client request. Therefore multiple client requests can be processed in parallel. An example of this model is shown in fig.8.7 (a)

enter image description here

enter image description here

enter image description here

 Fig 8.7 Models for Organizing Threads a) Dispatcher-worker Models; b) Team Model; c) Pipeline model.

2 ) Team Model : In this models, all threads behave as equals in the sense that there is no dispatcher-worker relationship for processing clients requests. Each threads gets and processes clients request on its own. This model is often used for implementing specialized threads within a process. That is, each thread of the process is specialized in servicing a specific type of request. Therefore, multiples types of requests can be simultaneously handled by the process. An example of this model is shown in figure 8.7(b).

3) Pipeline Model: This model is useful for applications based on the producer-consumer model, in which the output data generated by one part of the application is used as input for another part of the application. In this model, the threads of a process are organized as a pipeline so that output data generated by the first thread is used for processing by the second thread; the output of the second thread is used for processing by the third thread, and so on. The output of the last thread in the pipelines is the final output of the process to which the threads belong. An examples of this model is shown in figure 8.7(c)

Please log in to add an answer.