synchronization with eventcounts and sequencers
DESCRIPTION
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? - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/1.jpg)
Synchronization with Eventcounts and
Sequencers
David P. Reed
Rajendra K. Kanodia
![Page 2: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/2.jpg)
Introduction
What is it used for?
Synchronizing the use of shared resources
How is it different from semaphores and monitors?
Mutual exclusion
![Page 3: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/3.jpg)
EventCounts
What is an eventcount?
Tracks number of events
Non-decreasing integer variable
![Page 4: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/4.jpg)
EventCount operations
advance(E)
read(E)
await(E, v)
![Page 5: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/5.jpg)
advance( E )
Signals occurrence of an event
Update eventcount value
![Page 6: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/6.jpg)
read( E )
Returns value of eventcount
May or may not count events in progress
![Page 7: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/7.jpg)
await( E, v )
Similar to read( E )
Waits for value v to be reached
May not return immediately once the vth advance is executed
![Page 8: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/8.jpg)
Producer/Consumer Example
N-cell ring buffer
buffer[0:N –1]
Eventcounts IN and OUT
produce() to generate items
![Page 9: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/9.jpg)
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
![Page 10: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/10.jpg)
Single consumer codeProcedure consumer() begin integer i; for i := 1 to infinity begin await( IN, i ); consume( buffer[i mod N]); advance( OUT ); end end
Procedure producer()
begin integer i;
for i:= 1 to infinity do
begin
await( OUT, i – N);
buffer[i mod N] := produce( );
advance( IN );
end
![Page 11: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/11.jpg)
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.
![Page 12: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/12.jpg)
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.
![Page 13: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/13.jpg)
Sequencers
Used when synchronization requires arbitrationUsed to order the events Useful with Eventcounts but not on its own Non-decreasing integer value
![Page 14: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/14.jpg)
Sequencer operations
ticket(S) Value returned is the
process’s ordering. Two calls to ticket( S ) will
always return different values.
![Page 15: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/15.jpg)
Producer/Consumer Example
Same as with Eventcounts but multiple producers now
Sequencer T
Use ticket(T) to synchronize with other producers
![Page 16: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/16.jpg)
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
Procedure producer()
begin integer i;
for i:= 1 to infinity do
begin
await( OUT, i – N);
buffer[i mod N] := produce( );
advance( IN );
end
![Page 17: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/17.jpg)
Relation to semaphores
Lower level than Semaphores
Semaphores can be built from Eventcounts and Sequencers
![Page 18: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/18.jpg)
Semaphore Example
Semaphore S
EventCount is S.E
Sequencer is S.T
Initial value of S is S.I
![Page 19: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/19.jpg)
Semaphore Wait
Procedure P(S)
begin integer t;
t := ticket( S.T );
await( S.E, t – S.I );
end
![Page 20: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/20.jpg)
Semaphore Signal
Procedure V( S )
begin
advance( S.E )
end
![Page 21: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/21.jpg)
Deadlock Free Simultaneous P
2 Semaphores R and S
Global semaphore G to synchronize part of operation
![Page 22: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/22.jpg)
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
![Page 23: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/23.jpg)
Observations
G is used for obtaining tickets await operation could be deferredUseful in solving the Dining Philosophers Problem
![Page 24: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/24.jpg)
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
![Page 25: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/25.jpg)
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
![Page 26: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/26.jpg)
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
![Page 27: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/27.jpg)
Reader code
Procedure reader()
begin integer w;
abort: w := read(S);
await(C, w);
“read DB”
if read(S) ≠ w then goto abort;
end
![Page 28: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/28.jpg)
Writer code
Procedure writer()
begin integer t;
advance( S );
t := ticket( T );
await( C, t );
advance( C );
end
![Page 29: Synchronization with Eventcounts and Sequencers](https://reader036.vdocuments.us/reader036/viewer/2022062517/56814982550346895db6cc0a/html5/thumbnails/29.jpg)
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.