You are on page 1of 1

4.1 Provide two programming examples in which multithreading does not provide better performance than a single-threaded solution.

* More than one thread doing I/O on the same device (on an I/O bound task) * More than one thread using the same data that must be locked 4.2 Describe the actions taken by a thread library to context switch between user-level threads. * It has to save the stack and other local data, which it can easily do if it is written in assembly language, and load the stack etc for the process being switched to. 4.3 Under what circumstances does a multithreaded solution using multiple kernel threads provide better performance than a single-threaded solution on a single-processor system? * Generally, any situation where polling is avoided using the multithreading, allowing the thread to block rather than spinning on some condition(s). 4.4 Which of the following components of program state are shared across threads in a multithreaded process? (b) Heap memory, (c) Global variables. 4.5 Can a multithreaded solution using multiple user-level threads achieve better performance on a multiprocessor system than on a single-processor system? * No, because the kernel cannot tell the user-level threads apart from a single process, which is of course always run on one CPU. 4.6 As described in Section 4.5.2, Linux does not distinguish between processes and threads. Instead, Linux treats both in the same way, allowing a task to be more akin to a process or a thread depending on the set of flags passed to the clone() system call. However, many operating systemssuch as Windows XP and Solaristreat processes and threads differently. Typically, such systems use a notation wherein the data structure for a process contains pointers to the separate threads belonging to the process. Contrast these two approaches for modeling processes and threads within the kernel. * The Linux approach offers more flexibility than the Windows approach, but the Windows approach might be more programmer friendly if implemented correctly. 4.7 The program shown in Figure 4.11 uses the Pthreads API. What would be output from the program at LINE C and LINE P? * 5 and 0, respectively. (value is copied during the fork but not during the thread creation.) 4.8 Consider a multiprocessor system and a multithreaded program written using the many-to-many threading model. Let the number of user-level threads in the program be more than the number of processors in the system. Discuss the performance implications of the following scenarios. a. The number of kernel threads allocated to the program is less than the number of processors. * Some of the processors will remain idle at least part of the time. b. The number of kernel threads allocated to the program is equal to the number of processors. * This situation result in processors being idle when some thread has blocked. c. The number of kernel threads allocated to the program is greater than the number of processors but less than the number of user-level threads. * This situation should be fine, although the issues with user-level threads in general apply.

You might also like