11
CS162 Discussion sec/on Week 4

CS162Discussionsecon Week&4&cs162/sp11/... · SimpleResource& Allocaon&Graph& T 1 & T 2 & T 3 & R 1 & R 2 & R 3 & R 4 & Allocaon&Graph& With&Deadlock& T 1 & T 2 & T 3 & R 2 & R 1

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS162Discussionsecon Week&4&cs162/sp11/... · SimpleResource& Allocaon&Graph& T 1 & T 2 & T 3 & R 1 & R 2 & R 3 & R 4 & Allocaon&Graph& With&Deadlock& T 1 & T 2 & T 3 & R 2 & R 1

CS162  Discussion  sec/on  Week  4  

Page 2: CS162Discussionsecon Week&4&cs162/sp11/... · SimpleResource& Allocaon&Graph& T 1 & T 2 & T 3 & R 1 & R 2 & R 3 & R 4 & Allocaon&Graph& With&Deadlock& T 1 & T 2 & T 3 & R 2 & R 1

Overview  

•  Project  1  submissions  •  SVN  repository  setup  •  Synchroniza/on  in  Java  •  Monitors  

•  Deadlock  

Page 3: CS162Discussionsecon Week&4&cs162/sp11/... · SimpleResource& Allocaon&Graph& T 1 & T 2 & T 3 & R 1 & R 2 & R 3 & R 4 & Allocaon&Graph& With&Deadlock& T 1 & T 2 & T 3 & R 2 & R 1

Project  1  

•  Grading  –  Individual  por/on  (40%)  – Group  por/on  (60%)  

•  Group  por/on  breakdown  – First  draO  [10  points]  – Design  Review  [5  points]  – Final  design  doc  [25  points]  – Code  [60  points]  

Page 4: CS162Discussionsecon Week&4&cs162/sp11/... · SimpleResource& Allocaon&Graph& T 1 & T 2 & T 3 & R 1 & R 2 & R 3 & R 4 & Allocaon&Graph& With&Deadlock& T 1 & T 2 & T 3 & R 2 & R 1

Design  document  

•  Should  include…  –  Introduc/on  to  the  overall  behavior  of  the  system  – Technical  challenges  and  solu/ons  •  Solu/on  overview  (2-­‐4  lines)  •  Correctness  constraints  •  Data  structures  •  Design  decisions  •  Descrip/on  of  java  classes  and  methods  •  Pseudocode  for  key  algorithms  •  Test  plan  and  test  cases  

Page 5: CS162Discussionsecon Week&4&cs162/sp11/... · SimpleResource& Allocaon&Graph& T 1 & T 2 & T 3 & R 1 & R 2 & R 3 & R 4 & Allocaon&Graph& With&Deadlock& T 1 & T 2 & T 3 & R 2 & R 1

Design  document  (2)  

•  First  draO  should  be  between  1-­‐2k  lines  – Or  about  5-­‐10  pages  

•  Final  draO  should  be  2-­‐4k  lines  – 10-­‐20  pages  

•  Include  diagrams  that  show  interac/on  between  components  and  examples  

Page 6: CS162Discussionsecon Week&4&cs162/sp11/... · SimpleResource& Allocaon&Graph& T 1 & T 2 & T 3 & R 1 & R 2 & R 3 & R 4 & Allocaon&Graph& With&Deadlock& T 1 & T 2 & T 3 & R 2 & R 1

Four requirements for Deadlock"•  Mutual exclusion"–  Only one thread at a time can use a resource."

•  Hold and wait"–  Thread holding at least one resource is waiting to

acquire additional resources held by other threads"•  No preemption"–  Resources are released only voluntarily by the thread

holding the resource, after thread is finished with it"•  Circular wait"–  There exists a set {T1, …, Tn} of waiting threads"

•  T1 is waiting for a resource that is held by T2"•  T2 is waiting for a resource that is held by T3"•  …"•  Tn is waiting for a resource that is held by T1"

Page 7: CS162Discussionsecon Week&4&cs162/sp11/... · SimpleResource& Allocaon&Graph& T 1 & T 2 & T 3 & R 1 & R 2 & R 3 & R 4 & Allocaon&Graph& With&Deadlock& T 1 & T 2 & T 3 & R 2 & R 1

Symbols  

Resource-Allocation Graph"•  System Model " " " ""– A set of Threads T1, T2, . . ., Tn"– Resource types R1, R2, . . ., Rm"

!CPU cycles, memory space, I/O devices!– Each resource type Ri has Wi instances."– Each thread utilizes a resource as follows:"

•  Request() / Use() / Release() •  Resource-Allocation Graph:"– V is partitioned into two types:"

•  T = {T1, T2, …, Tn}, the set threads in the system."•  R = {R1, R2, …, Rm}, the set of resource types in system"

–  request edge – directed edge T1 → Rj!–  assignment edge – directed edge Rj → Ti!

R1  R2  

T1   T2  

Page 8: CS162Discussionsecon Week&4&cs162/sp11/... · SimpleResource& Allocaon&Graph& T 1 & T 2 & T 3 & R 1 & R 2 & R 3 & R 4 & Allocaon&Graph& With&Deadlock& T 1 & T 2 & T 3 & R 2 & R 1

Resource Allocation Graph Examples"

T1   T2   T3  

R1   R2  

R3  R4  

Simple  Resource  Alloca/on  Graph  

T1   T2   T3  

R1   R2  

R3  R4  

Alloca/on  Graph  With  Deadlock  

T1  

T2  

T3  

R2  

R1  

T4  

Alloca/on  Graph  With  Cycle,  but  No  Deadlock  

•  Recall:"–  request edge – directed edge T1 → Rj!– assignment edge – directed edge Rj → Ti!

Page 9: CS162Discussionsecon Week&4&cs162/sp11/... · SimpleResource& Allocaon&Graph& T 1 & T 2 & T 3 & R 1 & R 2 & R 3 & R 4 & Allocaon&Graph& With&Deadlock& T 1 & T 2 & T 3 & R 2 & R 1

Banker’s  algorithm(1)  

Page 10: CS162Discussionsecon Week&4&cs162/sp11/... · SimpleResource& Allocaon&Graph& T 1 & T 2 & T 3 & R 1 & R 2 & R 3 & R 4 & Allocaon&Graph& With&Deadlock& T 1 & T 2 & T 3 & R 2 & R 1

Banker’s  algorithm(2)  Safety  Check  

Page 11: CS162Discussionsecon Week&4&cs162/sp11/... · SimpleResource& Allocaon&Graph& T 1 & T 2 & T 3 & R 1 & R 2 & R 3 & R 4 & Allocaon&Graph& With&Deadlock& T 1 & T 2 & T 3 & R 2 & R 1

Banker’s  algorithm(3)  Request  Gran/ng