































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
































CompSci 143A
Spring, 2009
4.1 Kernel Definitions and Objects4.2 Queue Structures4.3 Threads4.4 Implementing Processes and Threads
4.5 Implementing Synchronization and Communication
Mechanisms– Requesting and Releasing Resources– Semaphores and Locks– Building Monitor Primitives– Clock and Time Management– Communications Kernel 4.6 Interrupt Handling
CompSci 143A
Spring, 2009
CompSci 143A
Spring, 2009
CompSci 143A
Spring, 2009
Priority Queues: Multiple queues
Figure 4-3(a)
CompSci 143A
Spring, 2009
Process has one or more threads
-^
All threads in a process share:– Memory space– Other resources
-^
Each thread has its own:– CPU state
(registers, program counter)
Implemented in user space orkernel space
-^
Threads are efficient, but lackprotection from each other
Figure 4-
CompSci 143A
Spring, 2009
Process status types
CompSci 143A
Spring, 2009
Implementing Processes and Threads•^
State
Diagram
Figure 4-
CompSci 143A
Spring, 2009
Create(s0, m0, pi, pid){
p = Get_New_PCB(); pid = Get_New_PID();p->ID = pid;
p->CPU_State = s0;
p->Memory = m0;
p->Priority = pi;
p->Status.Type = ’ready_s’;p->Status.List = RL;p->Creation_Tree.Parent = self;p->Creation_Tree.Child = NULL;insert(self-> Creation_Tree.Child, p);insert(RL, p);Scheduler(); }
CompSci 143A
Spring, 2009
Activate(pid){
p = Get_PCB(pid);if (p->Status.Type == ’ready_s’){
p->Status.Type = ’ready_a’;Scheduler(); } else p->Status.Type = ’blocked_a’; }
CompSci 143A
Spring, 2009
Process Operations:
Destroy
Destroy(pid){
p
=
Get_PCB(pid);
Kill_Tree(p);
Scheduler();}
Kill_Tree(p){
for
(each
q
in
p->Creation_Tree.Child)
Kill_Tree(q);
if
(p->Status.Type
==
’running
’)
{
cpu
=
p->Processor_ID;
Interrupt(cpu);
} Remove(p->Status.List,
p);
Release_all(p->Memory);Release_all(p->Other_Resources);Close_all(p->Open_Files);Delete_PCB(p);
}
CompSci 143A
Spring, 2009
Specific Instantiations of Resource Request, Release
CompSci 143A
Spring, 2009
CompSci 143A
Spring, 2009
Binary semaphore
sb
: only
or
Also known as a
spin lock
or a
spinning lock
(“Spinning”
“Busy Waiting”)
-^
Two atomic operations:
Pb
and
Vb
. Behavior is:
Pb(sb): if (sb==1) sb=0;
else wait until sb becomes 1
Vb(sb): sb=1;
-^
Indivisible implementation of
Pb
and
Vb
using
instruction:
Pb(sb): do (TS(R,sb)) while (!R);/wait loop/Vb(sb): sb=1;
-^
Note:
sb
is shared, but each process has its own
CompSci 143A
Spring, 2009
General Semaphores w/ busy wait
P(s) {
Inhibit_Interrupts;Pb(mutex_s);s = s-1;if (s < 0){
Vb(mutex_s);Enable_Interrupts;Pb(delay_s); } Vb(mutex_s);Enable_Interrupts; } V(s) {
Inhibit_Interrupts; Pb(mutex_s);s = s+1;if (s <= 0) Vb(delay_s);else Vb(mutex_s);Enable_Interrupts; }
-^
Inhibit_interrupt
prevents
deadlock due to contextswitching
-^
Two binary semaphores used:^ – delay_s
implements the
actual wait, and may beheld for a long time
needed to
implement critical sectionwith multiple CPUs, onlyheld for a few instructions
-^
Note than when
V
executes the
call
Pb(mutex_s)
, the
corresponding
Vb(mutex_s)
,
may be executed by
P