1 / 29

Synchronization with Eventcounts and Sequencers

Synchronization with Eventcounts and Sequencers. David P. Reed Rajendra K. Kanodia. Introduction. What is it used for? Synchronizing the use of shared resources How is it different from semaphores and monitors? Mutual exclusion. EventCounts. What is an eventcount?

elsu
Download Presentation

Synchronization with Eventcounts and Sequencers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Synchronization with Eventcounts and Sequencers David P. Reed Rajendra K. Kanodia

  2. Introduction • What is it used for? Synchronizing the use of shared resources • How is it different from semaphores and monitors? Mutual exclusion

  3. EventCounts • What is an eventcount? • Tracks number of events • Non-decreasing integervariable

  4. EventCount operations • advance(E) • read(E) • await(E, v)

  5. advance( E ) • Signals occurrence of an event • Update eventcount value

  6. read( E ) • Returns value of eventcount • May or may not count events in progress

  7. await( E, v ) • Similar to read( E ) • Waits for value v to be reached • May not return immediately once the vth advance is executed

  8. Producer/Consumer Example • N-cell ring buffer • buffer[0:N –1] • Eventcounts IN and OUT • produce() to generate items

  9. Single producer code Procedure producer() begin integer i; for i:= 1 to infinity do begin await( OUT, i – N); buffer[i mod N] := produce( ); advance( IN ); end end

  10. Single consumer code • Procedure producer() • begin integer i; • for i:= 1 to infinity do • begin • await( OUT, i – N); • buffer[i mod N] := produce( ); • advance( IN ); • end Procedure consumer() begin integer i; for i := 1 to infinity begin await( IN, i ); consume( buffer[i mod N]); advance( OUT ); end end

  11. Possible Situations • Fast Producer • Producer will wait until item it is trying to overwrite is consumed. • Fast Consumer • Consumer will wait until the producer has added the value.

  12. EventCount observations • How is this solution different than semaphores? • Relative ordering rather than mutual exclusion. • Producer & consumer can be concurrent. • Never does a process have to wait due to synchronization.

  13. Sequencers • Used when synchronization requires arbitration • Used to order the events • Useful with Eventcounts but not on its own • Non-decreasing integer value

  14. Sequencer operations • ticket(S) • Value returned is the process’s ordering. • Two calls to ticket( S ) will always return different values.

  15. Producer/Consumer Example • Same as with Eventcounts but multiple producers now • Sequencer T • Use ticket(T) to synchronize with other producers

  16. Procedure producer() • begin integer i; • for i:= 1 to infinity do • begin • await( OUT, i – N); • buffer[i mod N] := produce( ); • advance( IN ); • end Procedure producer() begin integer t; do forever begin t := ticket(T); await( IN, t); await( OUT, t – N + 1 ) buffer[t+1mod N] := produce( ); advance( IN ); end end

  17. Relation to semaphores • Lower level than Semaphores • Semaphores can be built from Eventcounts and Sequencers

  18. Semaphore Example • Semaphore S • EventCount is S.E • Sequencer is S.T • Initial value of S is S.I

  19. Semaphore Wait Procedure P(S) begin integer t; t := ticket( S.T ); await( S.E, t – S.I ); end

  20. Semaphore Signal Procedure V( S ) begin advance( S.E ) end

  21. Deadlock Free Simultaneous P • 2 Semaphores R and S • Global semaphore G to synchronize part of operation

  22. Procedure Pboth( R, S ) begin integer g, r, s; g := ticket( G.T ); await( G.E, g ); r := ticket( R.T ); s := ticket( S.T ); advance( G.E ); await( R.E, r – R.I ); await( S.E, s – S.I ); end

  23. Observations • G is used for obtaining tickets • await operation could be deferred • Useful in solving the Dining Philosophers Problem

  24. Observations • Process destroyed while holding 1 ticket • Keep the window during which a process has an unredeemed a ticket short • Don’t allow destroying the process during the window

  25. Flow of information • operations are: Observer or Signaler unlike the semaphore wait • Easily adapted to permissions • Observer permission(advance). • signaler permission(read,await). • Useful in secure systems

  26. Secure Readers - Writers • Shared database • Readers have observer permission • Writers have observer and signaler permission • Writer priority • S and C are eventcounts • T is a sequencer

  27. Reader code Procedure reader() begin integer w; abort: w := read(S); await(C, w); “read DB” if read(S) ≠ w then goto abort; end

  28. Writer code Procedure writer() begin integer t; advance( S ); t := ticket( T ); await( C, t ); advance( C ); end

  29. Conclusion • new mechanism for synchronization. • not based on mutual exclusion. • Provides an interface between processes. • Information flow paths are clear. • Effective in secure systems. • Unnecessary serialization avoided.

More Related