wys的个人博客

你有很多事放不下?做人要潇洒一点~

0%

Process Synchronization

Process Synchronization

5.1 In Section 5.4, we mentioned that disabling interrupts frequently can affect the system’s clock. Explain why this can occur and how such effects can be minimized. 在5.4节我们提到如果频繁的禁用中断会影响系统时钟,解释为什么会发生并把影响减到最小。

The system clock is updated at every clock interrupt. If interrupts were disabled—particularly for a long period of time—it is possible the system clock could easily lose the correct time. The system clock is also used for scheduling purposes. For example, the time quantum for a process is expressed as a number of clock ticks. At every clock interrupt, the scheduler determines if the time quantum for the currently running process has expired. If clock interrupts were disabled, the scheduler could not accurately assign time quantum. This effect can be minimized by disabling clock interrupts for only very short periods.

系统时钟被每一个时钟中断所更新,如果中断被禁止,特别是很长的时间,那么系统时钟会丢失掉当前时间。系统时钟还用于系统调度。例如,进程的时间量表示为时钟信号的数量,在每个系统中断时,调度程序确定当前运行的时间量是否已过期。如果时钟中断被禁用,调度程序将无法准确分配时间量。这种影响可以通过在每次禁用中断只禁用很短的时间来解决。

5.2 Explain why Windows, Linux, and Solaris implement multiple locking mechanisms. Describe the circumstances under which they use spin-locks, mutex locks, semaphores, adaptive mutex locks, and condition variables. In each case, explain why the mechanism is needed. 解释为什么windows,Linux 和 Solaris 实现多种锁机制。解释他们使用自旋锁,互斥锁信号量,自适应互斥锁和条件变量。在每种情况下,解释为什么这种锁机制是需要的。

These operating systems provide different locking mechanisms depending on the application developers’ needs. Spinlocks are useful for multiprocessor systems where a thread can run in a busy-loop (for a short period of time) rather than incurring the overhead of being put in a sleep queue. Mutexes are useful for locking resources. Solaris 2 uses adaptive mutexes, meaning that the mutex is implemented with a spin lock on multiprocessor machines. Semaphores and condition variables are more appropriate tools for synchronization when a resource must be held for a long period of time, since spinning is inefficient for a long duration.

这些操作系统提供了复杂的锁机制,依赖于应用开发者的需要。自旋锁对多处理器系统十分重要,因为对于自旋锁线程可以在忙等待运行而不是被放入睡眠队列,互斥锁对于锁资源非常重要。Solaris使用了自适应互斥锁意味着在多处理机上实现了自旋锁。信号量和条件变量对于同步来说更合适当资源需要被持有很长一段时间,因为自旋很长一段时间是低效的。

5.3 What is the meaning of the term busy waiting? What other kinds of waiting are there in an operating system? Can busy waiting be avoided

altogether? Explain your answer. 忙等待是什么意思,还有其他的什么等待,忙等待可以完全避免吗?

Busy waiting means that a process is waiting for a condition to be satisfied
in a tight loop without relinquishing the processor. Alternatively, a
process could wait by relinquishing the processor, and block on a
condition and wait to be awakened at some appropriate time in the
future. Busy waiting can be avoided but incurs the overhead associated
with putting a process to sleep and having to wake it up when the
appropriate program state is reached. 忙等待意味着进程在一个小的循环中等待条件满足而不放弃处理器。另外的一个进程可以放弃处理器并等待,他可以被条件阻塞然后在合适的时机被唤醒。可以避免忙等待但需花费将进程置于忙状态并将他唤醒的开销。

5.4 Explain why spinlocks are not appropriate for single-processor systems yet are often used in multiprocessor systems. 解释自旋锁为什么对单进程系统不合适并且经常使用在多处理器系统中。

Spinlocks are not appropriate for single-processor systems because the
condition that would break a process out of the spinlock can be obtained
only by executing a different process. If the process is not relinquishing
the processor, other processes do not get the opportunity to set the
program condition required for the first process to make progress. In a
multiprocessor system, other processes execute on other processors and
thereby modify the program state in order to release the first process
from the spinlock. 对于单进程系统,自旋锁不合适因为可以打破进程自旋锁的条件必须被一个正在执行的程序所持有。其他进程没有机会获得释放所得的条件。在多进程系统中,其他进程可以执行在其他处理器上,因此可以修改状态以释放自旋锁。