comp30112 concurrency
play

COMP30112: Concurrency Topics 5.4: Fairness and Starvation Howard - PowerPoint PPT Presentation

Topic 5.4: Fairness and Starvation COMP30112: Concurrency Topics 5.4: Fairness and Starvation Howard Barringer Room KB2.20: email: Howard.Barringer@manchester.ac.uk April 2008 Topic 5.4: Fairness and Starvation Outline Topic 5.4: Fairness


  1. Topic 5.4: Fairness and Starvation COMP30112: Concurrency Topics 5.4: Fairness and Starvation Howard Barringer Room KB2.20: email: Howard.Barringer@manchester.ac.uk April 2008

  2. Topic 5.4: Fairness and Starvation Outline Topic 5.4: Fairness and Starvation Readers and Writers Problem Properties for Reader/Writers Java implementation

  3. Topic 5.4: Fairness and Starvation Outline Topic 5.4: Fairness and Starvation Readers and Writers Problem Properties for Reader/Writers Java implementation

  4. Topic 5.4: Fairness and Starvation FSP Models • Database access and update • Several reader and writer processes • Simultaneous access where possible: multiple read, exclusive write • Avoid interference • Fairness, progress

  5. Topic 5.4: Fairness and Starvation

  6. Topic 5.4: Fairness and Starvation Modelling aspects Processes: • Readers • Writers • Database Properties: • Safety: No Readers have access when a Writer has access • Safety: Only one Writer has access at a time • Progress: Any Reader will eventually gain access • Progress: Any Writer will eventually gain access

  7. Topic 5.4: Fairness and Starvation An Abstract Model set Actions = {acquireRead, releaseRead, acquireWrite, releaseWrite} READER = ( acquireRead -> releaseRead -> READER ) + Actions. WRITER = ( acquireWrite -> releaseWrite -> WRITER ) + Actions. RW_LOCK = RW[0][False], RW[readers:0..Nread][writing:Bool] = ( when ( !writing ) acquireRead -> RW[readers+1][writing] | releaseRead -> RW[readers-1][writing] | when ( readers==0 && !writing ) acquireWrite -> RW[readers][True] | releaseWrite -> RW[readers][False] ).

  8. Topic 5.4: Fairness and Starvation LTS for RW LOCK

  9. Topic 5.4: Fairness and Starvation Outline Topic 5.4: Fairness and Starvation Readers and Writers Problem Properties for Reader/Writers Java implementation

  10. Topic 5.4: Fairness and Starvation Safety property SAFE_RW = ( acquireRead -> READING[1] | acquireWrite -> WRITING ), READING[i:1..Nread] = ( acquireRead -> READING[i+1] | when ( i>1 ) releaseRead -> READING[i-1] | when ( i==1 ) releaseRead -> SAFE_RW ), WRITING = ( releaseWrite -> SAFE_RW ). progress WRITE[i:1..Nwrite] = writer[i].acquireWrite progress READ[i:1..Nwrite] = reader[i].acquireRead

  11. Topic 5.4: Fairness and Starvation Checking Safety ||READWRITELOCK = (RW_LOCK || SAFE_RW). ||READERS_WRITERS = ( reader[1..Nread] :READER || writer[1..Nwrite]:WRITER || {reader[1..Nread],writer[1..Nwrite]}::READWRITELOCK ).

  12. Topic 5.4: Fairness and Starvation Progress Properties progress WRITE[i:1..Nwrite] = writer[i].acquireWrite progress READ[i:1..Nwrite] = reader[i].acquireRead ||RW_PROGRESS = READERS_WRITERS >> { reader[1..Nread].releaseRead, writer[1..Nread].releaseWrite }.

  13. Topic 5.4: Fairness and Starvation No Writer-Starvation Read/Write Lock RW_LOCK = RW[0][False][0], RW[readers:0..Nread][writing:Bool][waitingW:0..Nwrite] = ( when ( !writing && waitingW==0) acquireRead -> RW[readers+1][writing][waitingW] | releaseRead -> RW[readers-1][writing][waitingW] | when ( readers==0 && !writing ) acquireWrite -> RW[readers][True ][waitingW-1] | releaseWrite -> RW[readers][False][waitingW] | requestWrite -> RW[readers][False][waitingW+1] ).

  14. Topic 5.4: Fairness and Starvation Fair Read/Write Lock RW_LOCK = RW[0][False][0][False], RW[readers:0..Nread][writing:Bool] [waitingW:0..Nwrite][readersturn:Bool] = (when (!writing && (waitingW==0||readersturn)) acquireRead -> RW[readers+1][writing][waitingW][readersturn] | releaseRead -> RW[readers-1][writing][waitingW][False] | when ( readers==0 && !writing ) acquireWrite -> RW[readers][True ][waitingW-1][readersturn] | releaseWrite -> RW[readers][False][waitingW][True] | requestWrite -> RW[readers][writing][waitingW+1][readersturn] ).

  15. Topic 5.4: Fairness and Starvation Alternative Fair Read/Write Lock RW_LOCK = RW[0][0][False], RW[readers:0..Nread][waitingW:0..Nwrite][readersturn:Bool] = (when (waitingW==0||readersturn) acquireRead -> RW[readers+1][waitingW][readersturn] | releaseRead -> RW[readers-1][waitingW][False] | when ( readers==0 ) acquireWrite -> releaseWrite -> RW[readers][waitingW-1][True] | requestWrite -> RW[readers][waitingW+1][readersturn] ).

  16. Topic 5.4: Fairness and Starvation Outline Topic 5.4: Fairness and Starvation Readers and Writers Problem Properties for Reader/Writers Java implementation

  17. Topic 5.4: Fairness and Starvation Java Implementation: Safe class ReadWriteSafe implements ReadWrite { private int readers =0; private boolean writing = false; public synchronized void acquireRead() throws InterruptedException { while (writing) wait(); ++readers; } public synchronized void releaseRead() { --readers; if(readers==0) notify(); }

  18. Topic 5.4: Fairness and Starvation public synchronized void acquireWrite() throws InterruptedException { while (readers>0 || writing) wait(); writing = true; } public synchronized void releaseWrite() { writing = false; notifyAll(); }}

  19. Topic 5.4: Fairness and Starvation Java Implementation: No Writer Starvation class ReadWritePriority implements ReadWrite{ private int readers =0; private boolean writing = false; private int waitingW = 0; public synchronized void acquireRead() throws InterruptedException { while (writing || waitingW>0) wait(); ++readers; } public synchronized void releaseRead() { --readers; if (readers==0) notify(); }

  20. Topic 5.4: Fairness and Starvation public synchronized void acquireWrite() throws InterruptedException { ++waitingW; while (readers>0 || writing) wait(); --waitingW; writing = true; } public synchronized void releaseWrite() { writing = false; notifyAll(); }}

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend