东南大学《操作系统》课程作业 第四章

1 - Provide two programming examples in which multithreading does not provide better performance than a single-threaded solution.
一种是以串行操作为主的程序,例如对数字图像进行处理的各个步骤之间通常是无法并行的;
另一种是并行任务频率很大,需要频繁切换、同步、等待的程序,这样的程序在切换、同步、等待上的开销会带来更大的性能损失。

2 - Under what circumstances does a multithreaded solution using multiple kernel threads provide better performance than a single-threaded solution on a single-processor system?
对于一些处理任务单元之间不存在数据相互关联性的程序,如对数字图像进行最小值滤波,每一个滤波器所用的数据都是独立的N×N小块,此时可以多线程并行化处理,效率高于串行处理。
另外,考虑一种线程阻塞(如缺页错误或者系统调用)频繁发生的状况,单线程程序只能原地等待,而多线程程序的其他无关的线程可以继续执行。

3 - Which of the following components of program state are shared across threads in a multithreaded process?
a. Register values
b. Heap memory
c. Global variables
d. Stack memory

堆内存和全局变量是各个线程之间共享的。每个线程有自己的寄存器值和栈。

4 - Can a multithreaded solution using multiple user-level threads achieve better performance on a multiprocessor system than on a single-processor system? Explain.
对于多处理器系统和单处理器系统,决定核心利用率的是内核线程数量而不是用户级线程数量。以多对一模型为例,即使拥有再多的用户级线程,也只能同时运用一个内核。因此,多用户级线程在多处理器系统上并不能获得比单处理器更强的性能。

5 - Is it possible to have concurrency but not parallelism? Explain.
并发而不并行是可能的。并行只有在多核、多处理器系统上才可能真正实现,特点是多个任务或者线程同时在执行;并发在单核、单处理器系统上也可以实现,例如使用时间切片技术,整体上多个任务或者线程是一起执行的,但在特定瞬间只有一个任务或者线程执行。

6 - Using Amdahl’s Law, calculate the speedup gain for the following applications:
• 40 percent parallel with (a) eight processing cores and (b) sixteen processing cores
• 67 percent parallel with (a) two processing cores and (b) four processing cores
• 90 percent parallel with (a) four processing cores and (b) eight processing cores

image

7 - Consider a multicore system and a multithreaded program written using the many-to-many threading model. Let the number of user-level threads in the program be greater than the number of processing cores 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 processing cores.
b. The number of kernel threads allocated to the program is equal to the number of processing cores.
c. The number of kernel threads allocated to the program is greater than the number of processing cores but less than the number of user-level threads.

在多对多模型中,用户级线程被映射到内核线程,内核线程被映射到处理器核心。
当内核线程数量少于处理器核心数时,某些处理器核心会空闲,不能最大化利用机能;当内核线程数量等于处理器核心数时,理论上没有处理器核心空闲,可以最大化利用机能,除非内核线程因故发生阻塞(如系统调用);当内核线程数量大于处理器核心数时,内核线程需要轮流占用处理器核心,当某个内核线程阻塞时,可以交换为另一个内核线程占用处理器核心,可见这样更可能最大化利用机能。

原文地址:https://www.cnblogs.com/zxuuu/p/15628511.html