SGG 4

Read the corresponding sections in the SGG textbook and also the Pthread tutorial at LLNL.

4.1 Overview

  • What are the differences between a single-threaded and a multithreaded process? How do the two concepts compare as mechanisms for concurrent programming?
  • What is the data that is shared among the threads inside a single process?
  • What data does one multithreaded process share with other multithreaded processes?
  • How does multithreading increased the responsiveness of an application program?
  • Multithreading is supposed to lead to economy of memory because it facilitates resource sharing. Explain whether this statement is true and what resources are shared by threads of a single process.
  • Explain how creating multithreaded application programs become more scalable.
  • There are limits to how much parallelism one can get with multiprocessed and multithreaded applications. Use your best interpretation of Amdahl’s law to explain what limits speedup in parallelizing applications.

4.3 Multithreading models

  • Compare the many-to-one, one-to-one, and many-to-many models of mapping application threads to kernel threads. Explains the potential advantages and disadvantages of each of these models.

4.4 Thread Libraries

  • What is the difference between asynchronous threading and synchronous threading? Give examples of scenarios when one model is more desirable than the other.

4.4.1 Pthreads

  • In the C programming language, write the declaration of a function pointer with a predetermined type.
  • Can you explain the formal parameters in pthread_create(3)?
  • How can a thread wait for termination of another thread?
  • How can we build a multithreaded program that creates threads and waits for them all to terminate, similarly to what we’d do with fork(2)/wait(2) for processes?
  • Explain what happens if one of several threads in a process calls exit(3). Explain why this behavior might make sense.
  • What happens if one of several threads in a process calls exec(3).¬†Explain why this behavior might make sense.
  • What are the mechanisms available to threads that wish to communicate data to one another? How do we use them?
  • Compare what is stored in the state of a Unix process to what is stored in the state of a Pthread thread. Why is the amount of memory necessary for storing the state of a thread so much smaller?
  • Why don’t the multiple threads within a process share a common stack?
  • Why is it ok for the multiple threads within a process to have a common heap?
  • After a program creates multiple threads, what can you say about the order in which they are scheduled?

4.5.1 Thread Pools

  • If you create a separate thread to handle each incoming request in a server, you run a big risk: if an unreasonably large number of requests should arrive in short time, system resources such as memory and CPU time could get exhausted. Propose a solution to maintain high level of concurrency in the server that eliminates this risk.
  • What are the benefits of having a thread pool in comparison with creating threads dynamically when the need for them arises?
Print Friendly