【文章內(nèi)容簡介】
ther process run).P78 figure 22 Implementation of ProcessesProcess table:The structure of a process table Threads The Thread ModelThreadProcesses are used to group resources together。 threads are the entries scheduled for execution on the CPU. Thread Usage178。 The main reason for having threads is that in many applications, multiple activities are going on at once.178。 Second, they do not have any resources attached to them, they are easier to create and destroy than processes.178。 Third, they can improve performance of the system.178。 Finally, threads are useful on systems with multiple CPUs, where real parallelism is possible. Implement Threads in User SpaceIn user space: the kernel knows nothing about them, as far as the kernel is concerned, it is managing ordinary, singlethreaded processes. Implementing Threads in the KernelIn the kernel: the kernel know about and manage the threads. Hybrid Implementations課 堂 教 學(xué) 實 施 計 劃第4課教學(xué)過程設(shè)計: 復(fù) 習(xí) 5 分鐘;授新課 80 分鐘討 論 5 分鐘;其 它 0 分鐘授課類型(請打√):理論課□ 討論課□ 實驗課□ 習(xí)題課□ 其它□教學(xué)方式(請打√):講授□ 討論□ 示教□ 指導(dǎo)□ 其它□教學(xué)手段(請打√):多媒體□ 模型□ 實物□ 掛圖□ 音像□ 其它□教學(xué)內(nèi)容(包括基本內(nèi)容、重點、難點): Interprocess Communication Race ConditionsRace conditions: situations where two or more processes are reading or writing some shared data and the final result depends on who runs precisely when. Critical Regions178。 Mutual exclusion: that is some way of making sure that if one process is using a shared variable or file, the other processes will be excluded from doing the same thing178。 Make sure no two processes were ever in their critical sections at the same time.Critical region: is a part of the program where the memory is accessed. It also call critical section. Mutual Exclusion with Busy Waiting178。 Disabling interrupts178。 Lock variables178。 Strict alternation: P105 figure 220178。 Peterson’s solution: P106 figure 221 Sleep and Wakeup178。 Sleep is a system call that causes the caller to block, that is, be suspended until another process wakes it up.178。 Wakeup system call has one parameter, the process to be awakened.Use sleep and wakeup to solve producerconsumer problem: P109 figure 223.課 堂 教 學(xué) 實 施 計 劃第5課教學(xué)過程設(shè)計: 復(fù) 習(xí) 5 分鐘;授新課 85 分鐘討 論 0 分鐘;其 它 0 分鐘授課類型(請打√):理論課□ 討論課□ 實驗課□ 習(xí)題課□ 其它□教學(xué)方式(請打√):講授□ 討論□ 示教□ 指導(dǎo)□ 其它□教學(xué)手段(請打√):多媒體□ 模型□ 實物□ 掛圖□ 音像□ 其它□教學(xué)內(nèi)容(包括基本內(nèi)容、重點、難點): SemaphoresA semaphore could have the value 0, indicating that no wakeups were saved, or some positive value if one or more wakeups were pending.Semaphore’s description:typedef struct{int value。struct process *pointer。}semaphore, sem。A semaphore S can be accessed only through two standard atomic operations: down (P) and up (V). P and V are all atomic actions.A semaphore may be initialized to a nonnegative value.178。 The P operation decrements the semaphore value. If the value bees negative, then the process executing the P is blocked.178。 The V operation increments the semaphore values. If the value is not positive, then a process blocked by a P operation is unblocked.If the value of semaphore can be negative:P(s):{ 。if ( 0) { place this process in 。block this process。 }}V(s):{ ++。if ( =0) { remove a process from 。place the process on ready list。}}Two kinds of semaphores:178。 Mutual semaphores: that are initialized to 1 and used by two or more processes to ensure that only one of then can enter its critical region at the same time aver called binary semaphores.178。 Synchronization semaphores: are needed to guarantee that certain event sequences do or do not occur.The producerconsumer problem using semaphores: P112 figure 224. MonitorsCondition variable。 Wait (c)。 Signal (c) Message Passingsend (destination, amp。message)。receive (source, amp。message)。The producerconsumer problem with N messages: P120 figure 229.課 堂 教 學(xué) 實 施 計 劃第6課教學(xué)過程設(shè)計: 復(fù) 習(xí) 5 分鐘;授新課 85 分鐘討 論 0 分鐘;其 它 0 分鐘授課類型(請打√):理論課□ 討論課□ 實驗課□ 習(xí)題課□ 其它□教學(xué)方式(請打√):講授□ 討論□ 示教□ 指導(dǎo)□ 其它□教學(xué)手段(請打√):多媒體□ 模型□ 實物□ 掛圖□ 音像□ 其它□教學(xué)內(nèi)容(包括基本內(nèi)容、重點、難點): Classical IPC Problems The Dining Philosophers Problem The Readers and Writers Problem課 堂 教 學(xué) 實 施 計 劃第7課教學(xué)過程設(shè)計: 復(fù) 習(xí) 5 分鐘;授新課 85 分鐘討 論 0 分鐘;其 它 0 分鐘授課類型(請打√):理論課□ 討論課□ 實驗課□ 習(xí)題課□ 其它□教學(xué)方式(請打√):講授□ 討論□ 示教□ 指導(dǎo)□ 其它□教學(xué)手段(請打√):多媒體□ 模型□ 實物□ 掛圖□ 音像□ 其它□教學(xué)內(nèi)容(包括基本內(nèi)容、重點、難點): SchedulingSchedulerScheduling algorithm Introduce to SchedulingProcess behavior: CPUbound。 I/Obound.When to scheduling:178。 First, when a new process is created, a decision needs to be made whether to run the parent process or the child process.178。 Second, a scheduling decision must be made when a process exits.178。 Third, when a process blocks on I/O, on a semaphore, or for some other reason, another process has to be selected to run.178。 Fourth, when an I/O interrupt occurs, a scheduling decision may be made.Nonpreemptive: scheduling algorithm picks a process to run and then just lets it run until it blocks or until it voluntarily releases the CPU.Preemptive: scheduling algorithm picks a process and lets it run for a maximum of some fixed time.Categories of Scheduling Algorithms: P136178。 Batch178。 Interactive178。 Real timeScheduling Algorithm Goals: P137 figure 238All systems:178。 Fairness178。 Policy178。 BalanceBatch systems:178。 Throughput178。 Turnaround time178。 CPU utilizationInteractive systems:178。 Response time178。 ProportionallyRealtime systems:178。 Meeting deadlines178。 Predictability Scheduling in Batch Systems178。 FirstCome FirstServed (nonpreemptive):With this algorithm, jobs are assigned the CPU in the order they request it.Example:There are four jobs A, B, C, and D, with run times of 8, 6, 4, and 2