moir anderson sc495

Upload: rnadjette

Post on 30-May-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 Moir Anderson Sc495

    1/31

    W a i t - F r e e A l g o r i t h m s f o r F a s t , L o n g - L i v e d R e n a m i n g

    M a r k M o i r a n d J a m e s H . A n d e r s o n

    D e p a r t m e n t o f C o m p u t e r S c i e n c e

    T h e U n i v e r s i t y o f N o r t h C a r o l i n a a t C h a p e l H i l l

    C h a p e l H i l l , N o r t h C a r o l i n a 2 7 5 9 9 - 3 1 7 5 , U S A

    A u g u s t 1 9 9 4 r e v i s e d F e b r u a r y 1 9 9 5

    A b s t r a c t

    I n t h e c l a s s i c \ o n e - t i m e " r e n a m i n g p r o b l e m , p r o c e s s e s a r e r e q u i r e d t o c h o o s e n e w n a m e s i n o r d e r

    t o r e d u c e t h e s i z e o f t h e i r n a m e s p a c e . W e i n t r o d u c e a n e w , m o r e g e n e r a l v e r s i o n o f t h e r e n a m i n g

    p r o b l e m c a l l e d \ l o n g - l i v e d " r e n a m i n g , i n w h i c h p r o c e s s e s m a y r e p e a t e d l y a c q u i r e a n d r e l e a s e n a m e s . W e

    a l s o p r e s e n t s e v e r a l w a i t - f r e e a l g o r i t h m s f o r b o t h o n e - t i m e a n d w a i t - f r e e r e n a m i n g o n s h a r e d - m e m o r y

    m u l t i p r o c e s s i n g s y s t e m s . P r e v i o u s w a i t - f r e e r e n a m i n g a l g o r i t h m s h a v e t i m e c o m p l e x i t y t h a t i s d e p e n d e n t

    o n t h e s i z e o f t h e o r i g i n a l n a m e s p a c e . I n c o n t r a s t , m o s t o f o u r a l g o r i t h m s h a v e t i m e c o m p l e x i t y t h a t i s

    i n d e p e n d e n t o f t h e s i z e o f t h e o r i g i n a l n a m e s p a c e .

    1 I n t r o d u c t i o n

    I n t h e M - r e n a m i n g p r o b l e m 2 ] , e a c h o f k p r o c e s s e s i s r e q u i r e d t o c h o o s e a d i s t i n c t v a l u e , c a l l e d a n a m e

    t h a t r a n g e s o v e r f 0 : : : M ; 1 g . E a c h p r o c e s s i s a s s u m e d t o h a v e a u n i q u e p r o c e s s i d e n t i e r r a n g i n g o v e r

    f 0 : : : N ; 1 g . I t i s f u r t h e r r e q u i r e d t h a t k M < N . T h u s , a n M - r e n a m i n g a l g o r i t h m i s i n v o k e d b y k

    p r o c e s s e s i n o r d e r t o r e d u c e t h e s i z e o f t h e i r n a m e s p a c e f r o m N t o M

    R e n a m i n g i s u s e f u l w h e n p r o c e s s e s p e r f o r m a c o m p u t a t i o n w h o s e t i m e c o m p l e x i t y i s d e p e n d e n t o n t h e

    s i z e o f t h e n a m e s p a c e c o n t a i n i n g t h e p r o c e s s e s . B y r s t u s i n g a n e c i e n t r e n a m i n g a l g o r i t h m t o r e d u c e t h e

    s i z e o f t h e n a m e s p a c e , t h e t i m e c o m p l e x i t y o f t h a t c o m p u t a t i o n c a n b e m a d e i n d e p e n d e n t o f t h e s i z e o f t h e

    o r i g i n a l n a m e s p a c e .

    T h e r e n a m i n g p r o b l e m h a s b e e n s t u d i e d p r e v i o u s l y f o r b o t h m e s s a g e - p a s s i n g 2 ] a n d s h a r e d - m e m o r y

    m u l t i p r o c e s s i n g s y s t e m s 3 , 5 ] . I n t h i s p a p e r , w e c o n s i d e r w a i t - f r e e i m p l e m e n t a t i o n s o f r e n a m i n g i n a s y n -

    c h r o n o u s , s h a r e d - m e m o r y s y s t e m s . A r e n a m i n g a l g o r i t h m i s w a i t - f r e e i e a c h p r o c e s s i s g u a r a n t e e d t o a c q u i r e

    a n a m e a f t e r a n i t e n u m b e r o f t h a t p r o c e s s ' s s t e p s , e v e n i f o t h e r p r o c e s s e s h a l t u n d e t e c t a b l y .

    P r e v i o u s r e s e a r c h o n t h e r e n a m i n g p r o b l e m h a s f o c u s e d o n o n e - t i m e r e n a m i n g : e a c h p r o c e s s a c q u i r e s a

    n a m e o n l y o n c e . I n t h i s p a p e r , w e a l s o c o n s i d e r l o n g - l i v e d r e n a m i n g , a n e w , m o r e g e n e r a l v e r s i o n o f r e n a m i n g

    i n w h i c h p r o c e s s e s m a y r e p e a t e d l y a c q u i r e a n d r e l e a s e n a m e s .

    A s o l u t i o n t o t h e l o n g - l i v e d r e n a m i n g p r o b l e m i s u s e f u l i n s e t t i n g s i n w h i c h p r o c e s s e s r e p e a t e d l y a c c e s s

    i d e n t i c a l r e s o u r c e s . T h e s p e c i c a p p l i c a t i o n t h a t m o t i v a t e d u s t o s t u d y t h i s p r o b l e m i s t h e i m p l e m e n t a t i o n o f

    s h a r e d o b j e c t s . T h e c o m p l e x i t y o f a s h a r e d o b j e c t i m p l e m e n t a t i o n i s o f t e n d e p e n d e n t o n t h e s i z e o f t h e n a m e

    s p a c e c o n t a i n i n g t h e p r o c e s s e s t h a t a c c e s s t h a t i m p l e m e n t a t i o n . F o r s u c h i m p l e m e n t a t i o n s , p e r f o r m a n c e c a n

    b e i m p r o v e d b y r e s t r i c t i n g t h e n u m b e r o f p r o c e s s e s t h a t c o n c u r r e n t l y a c c e s s t h e i m p l e m e n t a t i o n , a n d b y

    W o r k s u p p o r t e d , i n p a r t , b y N S F C o n t r a c t C C R - 9 2 1 6 4 2 1 . A u t h o r s ' e - m a i l a d d r e s s e s : f m o i r , a n d e r s o n g @ c s . u n c . e d u . A

    p r e l i m i n a r y v e r s i o n 9 ] o f t h i s p a p e r w a s p r e s e n t e d a t t h e E i g h t h I n t e r n a t i o n a l W o r k s h o p o n D i s t r i b u t e d A l g o r i t h m s , T e r s c h e l l i n g ,

    T h e N e t h e r l a n d s , S e p t e m b e r , 1 9 9 4 .

    1

  • 8/14/2019 Moir Anderson Sc495

    2/31

    R e f e r e n c e M T i m e C o m p l e x i t y L o n g - L i v e d ?

    3 k ( k + 1 ) = 2 ( N k ) N o

    3 ] 2 k ; 1 ( N 4

    k

    ) N o

    5 ] 2 k ; 1 ( N k

    2

    ) N o

    T h m . 1 k ( k + 1 ) = 2 ( k ) N o

    T h m . 2 2 k ; 1 ( k

    4

    ) N o

    T h m . 3 k ( k + 1 ) = 2 ( N k ) Y e s

    T a b l e 1 : A c o m p a r i s o n o f w a i t - f r e e M - r e n a m i n g a l g o r i t h m s t h a t e m p l o y o n l y a t o m i c r e a d s a n d w r i t e s .

    u s i n g l o n g - l i v e d r e n a m i n g t o a c q u i r e a n a m e f r o m a r e d u c e d n a m e s p a c e . T h i s i s t h e e s s e n c e o f a n a p p r o a c h

    w e p r e v i o u s l y p r e s e n t e d f o r t h e i m p l e m e n t a t i o n o f r e s i l i e n t , s c a l a b l e s h a r e d o b j e c t s 1 ] . T h i s a p p r o a c h o n l y

    r e s t r i c t s t h e n u m b e r o f p r o c e s s e s t h a t a c c e s s t h e i m p l e m e n t a t i o n c o n c u r r e n t l y . O v e r t i m e , m a n y p r o c e s s e s

    m a y a c c e s s t h e i m p l e m e n t a t i o n . T h u s , i t i s n o t s u c i e n t t o s i m p l y a c q u i r e a n a m e o n c e a n d r e t a i n t h a t

    n a m e f o r f u t u r e u s e : a p r o c e s s m u s t b e a b l e t o r e l e a s e i t s n a m e s o t h a t a n o t h e r p r o c e s s m a y l a t e r a c q u i r e

    t h e s a m e n a m e . I n 1 ] , a s i m p l e l o n g - l i v e d r e n a m i n g a l g o r i t h m i s p r e s e n t e d i n o r d e r t o a d d r e s s t h i s i s s u e .

    T o o u r k n o w l e d g e , t h i s i s t h e o n l y p r e v i o u s w o r k o n l o n g - l i v e d r e n a m i n g . I n t h i s p a p e r , w e p r e s e n t s e v e r a l

    n e w l o n g - l i v e d r e n a m i n g a l g o r i t h m s , o n e o f w h i c h i s a g e n e r a l i z a t i o n o f t h e a l g o r i t h m p r e s e n t e d i n 1 ] .

    I n t h e r s t p a r t o f t h e p a p e r , w e p r e s e n t r e n a m i n g a l g o r i t h m s t h a t u s e o n l y a t o m i c r e a d a n d w r i t e

    i n s t r u c t i o n s . I t h a s b e e n s h o w n t h a t i f M

  • 8/14/2019 Moir Anderson Sc495

    3/31

    R e f e r e n c e T i m e C o m p l e x i t y B i t s / V a r i a b l e I n s t r u c t i o n s U s e d

    T h m . 4 ( k ) 1 w r i t e a n d t e s t a n d s e t

    T h m . 4 ( k = b ) b s e t r s t z e r o a n d c l r b i t

    T h m . 5 ( l o g k ) ( l o g k ) b o u n d e d d e c r e m e n t a n d f e t c h a n d a d d

    T h m . 6 ( l o g ( k = b ) ) ( l o g k ) b o u n d e d d e c r e m e n t , f e t c h a n d a d d , s e t r s t z e r o , a n d c l r b i t

    T a b l e 2 : A c o m p a r i s o n o f w a i t - f r e e l o n g - l i v e d k - r e n a m i n g a l g o r i t h m s .

    B B N T C 2 0 0 0 m u l t i p r o c e s s o r 4 ] . T h e c l r b i t ( X i ) o p e r a t i o n c l e a r s t h e i t h b i t o f t h e b - b i t s h a r e d v a r i a b l e

    X . F o r b = 1 c l r b i t i s a s i m p l e w r i t e o p e r a t i o n . F o r b > 1 c l r b i t c a n b e i m p l e m e n t e d , f o r e x a m p l e , u s i n g

    t h e f e t c h a n d a n d o p e r a t i o n a v a i l a b l e o n t h e B B N T C 2 0 0 0 .

    O u r s e c o n d l o n g - l i v e d k - r e n a m i n g a l g o r i t h m e m p l o y s t h e c o m m o n l y - a v a i l a b l e f e t c h a n d a d d o p e r a t i o n

    a n d t h e b o u n d e d d e c r e m e n t o p e r a t i o n . T h e b o u n d e d d e c r e m e n t o p e r a t i o n i s s i m i l a r t o f e t c h a n d a d d ( X ; 1 )

    e x c e p t t h a t b o u n d e d d e c r e m e n t d o e s n o t m o d i f y a v a r i a b l e w h o s e v a l u e i s z e r o . W e d o n o t k n o w o f a n y

    s y s t e m s t h a t p r o v i d e b o u n d e d d e c r e m e n t a s a p r i m i t i v e o p e r a t i o n . H o w e v e r , a t t h e e n d o f S e c t i o n 5 , w e

    s h o w t h a t b o u n d e d d e c r e m e n t c a n b e a p p r o x i m a t e d i n a l o c k - f r e e m a n n e r u s i n g t h e f e t c h a n d a d d o p e r a t i o n .

    T h i s a l l o w s u s t o o b t a i n a l o c k - f r e e , l o n g - l i v e d k - r e n a m i n g a l g o r i t h m b a s e d o n f e t c h a n d a d d . A r e n a m i n g

    a l g o r i t h m i s l o c k - f r e e i i t i s g u a r a n t e e d t h a t e a c h a t t e m p t b y s o m e p r o c e s s p t o a c q u i r e o r r e l e a s e a n a m e

    t e r m i n a t e s u n l e s s s o m e o t h e r p r o c e s s a c q u i r e s a n d r e l e a s e s a n a m e i n n i t e l y o f t e n .

    O u r t h i r d l o n g - l i v e d k - r e n a m i n g a l g o r i t h m c o m b i n e s b o t h a l g o r i t h m s d i s c u s s e d a b o v e , i m p r o v i n g o n t h e

    p e r f o r m a n c e o f e a c h . O u r w a i t - f r e e , l o n g - l i v e d k - r e n a m i n g a l g o r i t h m s a r e s u m m a r i z e d i n T a b l e 2 .

    T h e r e m a i n d e r o f t h e p a p e r i s o r g a n i z e d a s f o l l o w s . S e c t i o n 2 c o n t a i n s d e n i t i o n s u s e d i n t h e r e s t o f

    t h e p a p e r . I n S e c t i o n s 3 a n d 4 , w e p r e s e n t o n e - t i m e a n d l o n g - l i v e d r e n a m i n g a l g o r i t h m s t h a t e m p l o y o n l y

    a t o m i c r e a d s a n d w r i t e s . I n S e c t i o n 5 , w e p r e s e n t l o n g - l i v e d r e n a m i n g a l g o r i t h m s t h a t e m p l o y s t r o n g e r

    r e a d - m o d i f y - w r i t e o p e r a t i o n s . C o n c l u d i n g r e m a r k s a p p e a r i n S e c t i o n 6 .

    2 D e n i t i o n s

    O u r p r o g r a m m i n g n o t a t i o n s h o u l d b e s e l f - e x p l a n a t o r y a s a n e x a m p l e o f t h i s n o t a t i o n , s e e F i g u r e 2 . I n t h i s

    a n d s u b s e q u e n t g u r e s , e a c h l a b e l e d p r o g r a m f r a g m e n t i s a s s u m e d t o b e a t o m i c ,

    1

    u n l e s s n o l a b e l s a r e g i v e n ,

    i n w h i c h c a s e e a c h l i n e o f c o d e i s a s s u m e d t o b e a t o m i c .

    N o t a t i o n a l C o n v e n t i o n s : W e a s s u m e t h a t 1 < k M < N , a n d t h a t p a n d q r a n g e o v e r 0 : : : N ; 1

    O t h e r f r e e v a r i a b l e s a r e a s s u m e d t o b e u n i v e r s a l l y q u a n t i e d . W e u s e P

    x

    1

    x

    2

    : : : x

    n

    y

    1

    y

    2

    : : : y

    n

    t o d e n o t e t h e e x p r e s s i o n

    P w i t h e a c h o c c u r r e n c e o f x

    i

    r e p l a c e d b y y

    i

    . T h e p r e d i c a t e p @ s h o l d s i s t a t e m e n t s i s t h e n e x t s t a t e m e n t

    t o b e e x e c u t e d b y p r o c e s s p . W e u s e p @ S a s s h o r t h a n d f o r ( 9 s s 2 S p @ s ) p s t o d e n o t e s t a t e m e n t s o f

    p r o c e s s p , a n d p v a r t o d e n o t e p ' s l o c a l v a r i a b l e v a r . T h e f o l l o w i n g i s a l i s t o f s y m b o l s w e u s e i n o u r p r o o f s ,

    i n i n c r e a s i n g o r d e r o f b i n d i n g p o w e r : ) _ ( = 6= < > ) , ( + ; ) , ( m u l t i p l i c a t i o n , = ) : ( @ )

    ( f g ) . S y m b o l s i n p a r e n t h e s e s h a v e t h e s a m e b i n d i n g p o w e r . W e s o m e t i m e s u s e p a r e n t h e s e s t o o v e r r i d e

    t h e s e b i n d i n g r u l e s . W e s o m e t i m e s u s e H o a r e t r i p l e s 6 ] t o d e n o t e t h e e e c t s o f a s t a t e m e n t e x e c u t i o n . 2

    I n t h e o n e - t i m e M - r e n a m i n g p r o b l e m , e a c h o f k p r o c e s s e s , w i t h d i s t i n c t p r o c e s s i d e n t i e r s r a n g i n g o v e r

    f 0 : : : N ; 1 g , c h o o s e s a d i s t i n c t v a l u e r a n g i n g o v e r f 0 : : : M ; 1 g . A s o l u t i o n t o t h e M - r e n a m i n g p r o b l e m

    1

    T o s i m p l i f y o u r p r o o f s , w e s o m e t i m e s l a b e l s o m e w h a t l e n g t h y b l o c k s o f c o d e . N o n e t h e l e s s , s u c h c o d e b l o c k s a r e i n k e e p i n g

    w i t h t h e a t o m i c i n s t r u c t i o n s u s e d . F o r e x a m p l e , s t a t e m e n t 3 i n F i g u r e 4 i s a s s u m e d t o a t o m i c a l l y r e a d X i j ] , a s s i g n s t o p = t r u e

    o r i = i + 1 d e p e n d i n g o n t h e v a l u e r e a d , c h e c k t h e l o o p c o n d i t i o n , a n d s e t t h e p r o g r a m c o u n t e r o f t h e e x e c u t i n g p r o c e s s t o 0

    o r 4 , a c c o r d i n g l y . N o t e , h o w e v e r , t h a t X i j ] i s t h e o n l y s h a r e d v a r i a b l e a c c e s s e d b y s t a t e m e n t 3 . B e c a u s e a l l o t h e r v a r i a b l e s

    a c c e s s e d b y t h i s s t a t e m e n t a r e p r i v a t e , s t a t e m e n t 3 c a n b e e a s i l y i m p l e m e n t e d u s i n g a s i n g l e a t o m i c r e a d o f a s h a r e d v a r i a b l e .

    T h i s i s i n k e e p i n g w i t h t h e r e a d / w r i t e a t o m i c i t y a s s u m e d f o r t h i s a l g o r i t h m .

    3

  • 8/14/2019 Moir Anderson Sc495

    4/31

    p r o c e s s p = 0 p < N =

    p r i v a t e v a r i a b l e n a m e 0 M ; 1 = N a m e r e c e i v e d =

    w h i l e t r u e d o

    R e m a i n d e r S e c t i o n = E n s u r e a t m o s t k p r o c e s s e s r e n a m e c o n c u r r e n t l y =

    G e t n a m e S e c t i o n = A s s i g n s a v a l u e r a n g i n g o v e r f 0 : : : M ; 1 g t o p n a m e =

    W o r k i n g S e c t i o n

    P u t n a m e S e c t i o n = R e l e a s e t h e n a m e o b t a i n e d =

    o d

    F i g u r e 1 : O r g a n i z a t i o n o f p r o c e s s e s a c c e s s i n g a l o n g - l i v e d r e n a m i n g a l g o r i t h m .

    c o n s i s t s o f a w a i t - f r e e c o d e f r a g m e n t f o r e a c h p r o c e s s p t h a t a s s i g n s a v a l u e r a n g i n g o v e r f 0 : : : M ; 1 g t o a

    p r i v a t e v a r i a b l e p n a m e a n d t h e n h a l t s . F o r p 6= q , t h e s a m e v a l u e s h o u l d n o t b e a s s i g n e d t o b o t h p n a m e

    a n d q n a m e

    I n t h e l o n g - l i v e d M - r e n a m i n g p r o b l e m , e a c h o f N d i s t i n c t p r o c e s s e s r e p e a t e d l y e x e c u t e s a r e m a i n d e r

    s e c t i o n , a c q u i r e s a n a m e b y e x e c u t i n g a g e t n a m e s e c t i o n , u s e s t h a t n a m e i n a w o r k i n g s e c t i o n , a n d t h e n

    r e l e a s e s t h e n a m e b y e x e c u t i n g a p u t n a m e s e c t i o n . T h e o r g a n i z a t i o n o f t h e s e p r o c e s s e s i s s h o w n i n F i g u r e 1 .

    I t i s a s s u m e d t h a t e a c h p r o c e s s i s i n i t i a l l y i n i t s r e m a i n d e r s e c t i o n , a n d t h a t t h e r e m a i n d e r s e c t i o n g u a r a n t e e s

    t h a t a t m o s t k p r o c e s s e s a r e o u t s i d e t h e i r r e m a i n d e r s e c t i o n s a t a n y t i m e . A s o l u t i o n t o t h e l o n g - l i v e d M -

    r e n a m i n g p r o b l e m c o n s i s t s o f w a i t - f r e e c o d e f r a g m e n t s t h a t i m p l e m e n t t h e g e t n a m e a n d p u t n a m e s e c t i o n s

    s h o w n i n F i g u r e 1 , a l o n g w i t h a s s o c i a t e d s h a r e d v a r i a b l e s . T h e g e t n a m e s e c t i o n f o r p r o c e s s p i s r e q u i r e d

    t o a s s i g n a v a l u e r a n g i n g o v e r f 0 : : : M ; 1 g t o p n a m e . I f d i s t i n c t p r o c e s s e s p a n d q a r e i n t h e i r w o r k i n g

    s e c t i o n s , t h e n i t i s r e q u i r e d t h a t p n a m e 6= q n a m e

    A s d i s c u s s e d i n t h e i n t r o d u c t i o n , o u r a l g o r i t h m s u s e t h e s e t r s t z e r o c l r b i t , a n d b o u n d e d d e c r e m e n t

    o p e r a t i o n s , a m o n g o t h e r w e l l - k n o w n o p e r a t i o n s . W e d e n e t h e s e o p e r a t i o n s f o r m a l l y b y t h e f o l l o w i n g a t o m i c

    c o d e f r a g m e n t s , w h e r e X i s a b - b i t s h a r e d v a r i a b l e w h o s e b i t s a r e i n d e x e d f r o m 0 t o b ; 1 , a n d Y i s a n o n -

    n e g a t i v e i n t e g e r . W e s t r e s s t h a t t h e s e c o d e f r a g m e n t s a r e d e n i t i o n s , a n d s h o u l d n o t b e i n t e r p r e t e d a s

    i m p l e m e n t a t i o n s o f t h e g i v e n o p e r a t i o n s .

    s e t r s t z e r o ( X ) i f ( 9 n 0 n < b : X n ) t h e n

    m : = ( m i n n 0 n < b : X n ) X m = t r u e r e t u r n m

    e l s e

    r e t u r n b

    c l r b i t ( X i ) X i = f a l s e

    b o u n d e d d e c r e m e n t ( Y ) m = Y i f Y 6= 0 t h e n Y = Y ; 1 r e t u r n m

    I n e a c h o f o u r a l g o r i t h m s , e a c h a t o m i c a l l y - a c c e s s i b l e s h a r e d v a r i a b l e c a n b e s t o r e d i n o n e m a c h i n e w o r d f o r

    a l l r e a s o n a b l e v a l u e s o f N . F o r e x a m p l e , o u r r e a d / w r i t e a l g o r i t h m s r e q u i r e s h a r e d v a r i a b l e s o f a p p r o x i m a t e l y

    l o g

    2

    N b i t s . T h u s , o n a 3 2 - b i t s h a r e d - m e m o r y m u l t i p r o c e s s o r , t h e s e s h a r e d v a r i a b l e s c a n b e a c c e s s e d w i t h

    o n e s h a r e d v a r i a b l e a c c e s s i f N

  • 8/14/2019 Moir Anderson Sc495

    5/31

    n

    n1

    n1

    1

    stop right

    down

    s h a r e d v a r i a b l e X f ? g f 0 N ; 1 g

    Y b o o l e a n

    i n i t i a l l y X = ? Y = f a l s e

    p r i v a t e v a r i a b l e m o v e f s t o p r i g h t d o w n g

    X = p

    i f Y t h e n m o v e = r i g h t

    e l s e

    Y = t r u e

    i f X = p t h e n m o v e = s t o p

    e l s e m o v e = d o w n

    F i g u r e 2 : T h e o n e - t i m e b u i l d i n g b l o c k a n d t h e c o d e f r a g m e n t t h a t i m p l e m e n t s i t .

    a l g o r i t h m . B o t h a l g o r i t h m s a r e a l s o o f i n t e r e s t i n t h e i r o w n r i g h t , b e c a u s e t h e y s i g n i c a n t l y i m p r o v e o v e r

    p r e v i o u s r e a d / w r i t e a l g o r i t h m s f o r o n e - t i m e r e n a m i n g .

    W e s t a r t b y p r e s e n t i n g a o n e - t i m e ( k ( k + 1 ) = 2 ) - r e n a m i n g a l g o r i t h m t h a t h a s ( k ) t i m e c o m p l e x i t y . W e

    t h e n d e s c r i b e h o w t h i s a l g o r i t h m c a n b e c o m b i n e d w i t h p r e v i o u s r e s u l t s 5 ] t o o b t a i n a ( 2 k ; 1 ) - r e n a m i n g

    a l g o r i t h m w i t h ( k

    4

    ) t i m e c o m p l e x i t y . I t h a s b e e n s h o w n t h a t r e n a m i n g i s i m p o s s i b l e f o r f e w e r t h a n 2 k ; 1

    n a m e s w h e n u s i n g o n l y r e a d s a n d w r i t e s s o , w i t h r e s p e c t t o t h e s i z e o f t h e r e s u l t i n g n a m e s p a c e , t h i s

    a l g o r i t h m i s o p t i m a l . O u r o n e - t i m e ( k ( k + 1 ) = 2 ) - r e n a m i n g a l g o r i t h m i s b a s e d o n a \ b u i l d i n g b l o c k " , w h i c h

    w e d e s c r i b e n e x t .

    3 . 1 T h e O n e - T i m e B u i l d i n g B l o c k

    T h e o n e - t i m e b u i l d i n g b l o c k , d e p i c t e d i n F i g u r e 2 , i s i n t h e f o r m o f a w a i t - f r e e c o d e f r a g m e n t t h a t a s s i g n s

    t o a p r i v a t e v a r i a b l e m o v e o n e o f t h r e e v a l u e s : s t o p r i g h t o r d o w n . I f e a c h o f n p r o c e s s e s e x e c u t e s t h i s c o d e

    f r a g m e n t a t m o s t o n c e , t h e n a t m o s t o n e p r o c e s s r e c e i v e s a v a l u e o f s t o p , a t m o s t n ; 1 p r o c e s s e s r e c e i v e a

    v a l u e o f r i g h t , a n d a t m o s t n ; 1 p r o c e s s e s r e c e i v e a v a l u e o f d o w n . W e s a y t h a t a p r o c e s s t h a t r e c e i v e s a

    v a l u e o f d o w n \ g o e s d o w n " , a p r o c e s s t h a t r e c e i v e s a v a l u e o f r i g h t \ g o e s r i g h t " , a n d a p r o c e s s t h a t r e c e i v e s

    a v a l u e o f s t o p \ s t o p s " . F i g u r e 2 s h o w s n p r o c e s s e s a c c e s s i n g a b u i l d i n g b l o c k , a n d t h e m a x i m u m n u m b e r o f

    p r o c e s s e s t h a t r e c e i v e e a c h v a l u e .

    T h e c o d e f r a g m e n t s h o w n i n F i g u r e 2 s h o w s h o w t h e b u i l d i n g b l o c k c a n b e i m p l e m e n t e d u s i n g a t o m i c

    r e a d a n d w r i t e o p e r a t i o n s . T h e t e c h n i q u e e m p l o y e d i s e s s e n t i a l l y t h a t o f t h e \ f a s t p a t h " m e c h a n i s m u s e d i n

    L a m p o r t ' s f a s t m u t u a l e x c l u s i o n a l g o r i t h m 8 ] . A p r o c e s s t h a t s t o p s c o r r e s p o n d s t o a p r o c e s s s u c c e s s f u l l y

    \ t a k i n g t h e f a s t p a t h " i n L a m p o r t ' s a l g o r i t h m . T h e v a l u e a s s i g n e d t o m o v e b y a p r o c e s s p t h a t f a i l s t o \ t a k e

    t h e f a s t p a t h " i s d e t e r m i n e d b y t h e b r a n c h p t a k e s : i f p d e t e c t s t h a t Y h o l d s , t h e n p g o e s r i g h t , a n d i f p

    d e t e c t s t h a t X 6= p h o l d s , t h e n p g o e s d o w n .

    T o s e e w h y t h e c o d e f r a g m e n t s h o w n i n F i g u r e 2 s a t i s e s t h e r e q u i r e m e n t s o f o u r b u i l d i n g b l o c k , r s t

    n o t e t h a t i t i s i m p o s s i b l e f o r a l l n p r o c e s s e s t o g o r i g h t | a p r o c e s s c a n g o r i g h t o n l y i f a n o t h e r p r o c e s s

    p r e v i o u s l y a s s i g n e d Y = t r u e . S e c o n d , t h e l a s t p r o c e s s p t o a s s i g n X = p c a n n o t g o d o w n b e c a u s e i f i t

    t e s t s X , t h e n i t d e t e c t s t h a t X = p a n d t h e r e f o r e s t o p s . T h u s , i t i s i m p o s s i b l e f o r a l l n p r o c e s s e s t o g o

    5

  • 8/14/2019 Moir Anderson Sc495

    6/31

    0 1 2 3 4

    8

    9 10 11

    12 13

    14

    6 75

    F i g u r e 3 : k ( k ; 1 ) = 2 b u i l d i n g b l o c k s i n a g r i d , d e p i c t e d f o r k = 5

    d o w n . F i n a l l y , b e c a u s e L a m p o r t ' s a l g o r i t h m p r e v e n t s m o r e t h a n o n e p r o c e s s e s f r o m \ t a k i n g t h e f a s t p a t h " ,

    i t i s i m p o s s i b l e f o r m o r e t h a n o n e p r o c e s s t o s t o p .

    I n t h e n e x t s e c t i o n , w e s h o w h o w t h e s e b u i l d i n g b l o c k s c a n b e u s e d t o s o l v e t h e r e n a m i n g p r o b l e m . T h e

    b a s i c a p p r o a c h i s t o u s e s u c h b u i l d i n g b l o c k s t o \ s p l i t " p r o c e s s e s i n t o s u c c e s s i v e l y s m a l l e r g r o u p s . B e c a u s e

    a t m o s t o n e p r o c e s s s t o p s a t a n y p a r t i c u l a r b u i l d i n g b l o c k , a p r o c e s s t h a t s t o p s c a n b e g i v e n a u n i q u e n a m e

    a s s o c i a t e d w i t h t h a t b u i l d i n g b l o c k . F u r t h e r m o r e , w h e n t h e s i z e o f a g r o u p h a s b e e n d e c r e a s e d e n o u g h t i m e s

    t h a t a t m o s t o n e p r o c e s s r e m a i n s , t h a t p r o c e s s ( i f i t e x i s t s ) c a n b e g i v e n a n a m e i m m e d i a t e l y .

    3 . 2 U s i n g t h e O n e - T i m e B u i l d i n g B l o c k t o S o l v e R e n a m i n g

    I n t h i s s e c t i o n , w e u s e k ( k ; 1 ) = 2 o n e - t i m e b u i l d i n g b l o c k s a r r a n g e d i n a \ g r i d " t o s o l v e o n e - t i m e r e n a m i n g

    t h i s a p p r o a c h i s d e p i c t e d i n F i g u r e 3 f o r k = 5 . I n o r d e r t o a c q u i r e a n a m e , a p r o c e s s p a c c e s s e s t h e b u i l d i n g

    b l o c k a t t h e t o p l e f t c o r n e r o f t h e g r i d . I f p r e c e i v e s a v a l u e o f s t o p , t h e n p a c q u i r e s t h e n a m e a s s o c i a t e d w i t h

    t h a t b u i l d i n g b l o c k . O t h e r w i s e , p m o v e s e i t h e r r i g h t o r d o w n i n t h e g r i d , a c c o r d i n g t o t h e v a l u e r e c e i v e d .

    T h i s i s r e p e a t e d u n t i l p r e c e i v e s a v a l u e o f s t o p a t s o m e b u i l d i n g b l o c k , o r p h a s a c c e s s e d k ; 1 b u i l d i n g b l o c k s .

    T h e n a m e r e t u r n e d i s c a l c u l a t e d b a s e d o n p ' s n a l p o s i t i o n i n t h e g r i d . I n F i g u r e 3 , e a c h g r i d p o s i t i o n i s

    l a b e l e d w i t h t h e n a m e a s s o c i a t e d w i t h t h a t p o s i t i o n . B e c a u s e n o p r o c e s s t a k e s m o r e t h a n k ; 1 s t e p s , o n l y

    t h e u p p e r l e f t t r i a n g l e o f t h e g r i d i s u s e d , a s s h o w n i n F i g u r e 3 .

    T h e a l g o r i t h m i s p r e s e n t e d m o r e f o r m a l l y i n F i g u r e 4 . N o t e t h a t e a c h b u i l d i n g b l o c k i n t h e g r i d i s

    i m p l e m e n t e d u s i n g t h e c o d e f r a g m e n t s h o w n i n F i g u r e 2 . A t m o s t o n e p r o c e s s s t o p s a t e a c h b u i l d i n g b l o c k ,

    s o a p r o c e s s t h a t s t o p s a t a b u i l d i n g b l o c k r e c e i v e s a u n i q u e n a m e . H o w e v e r , a p r o c e s s m a y a l s o o b t a i n a

    n a m e b y t a k i n g k ; 1 s t e p s i n t h e g r i d . I n A p p e n d i x A , w e s h o w t h a t d i s t i n c t p r o c e s s e s t h a t t a k e k ; 1 s t e p s

    i n t h e g r i d a c q u i r e d i s t i n c t n a m e s . S p e c i c a l l y , i n v a r i a n t ( I 9 ) i n A p p e n d i x A i m p l i e s t h a t n o t w o p r o c e s s e s

    a r r i v e a t t h e s a m e g r i d p o s i t i o n a f t e r t a k i n g k ; 1 s t e p s i n t h e g r i d . W e a l s o p r o v e t h a t e a c h p r o c e s s a c q u i r e s

    a n a m e f r o m f 0 : : : k ( k + 1 ) = 2 ; 1 g ( s e e ( I 1 4 ) ) , a f t e r a c c e s s i n g a t m o s t 4 ( k ; 1 ) s h a r e d v a r i a b l e s . T h u s , w e

    h a v e t h e f o l l o w i n g r e s u l t .

    T h e o r e m 1 : U s i n g r e a d a n d w r i t e , w a i t - f r e e , o n e - t i m e ( k ( k + 1 ) = 2 ) - r e n a m i n g c a n b e i m p l e m e n t e d s o t h a t

    t h e w o r s t - c a s e t i m e c o m p l e x i t y o f a c q u i r i n g a n a m e o n c e i s 4 ( k ; 1 ) 2

    6

  • 8/14/2019 Moir Anderson Sc495

    7/31

    s h a r e d v a r i a b l e X a r r a y 0 k ; 2 0 k ; 2 o f f ? g f 0 N ; 1 g

    Y a r r a y 0 k ; 2 0 k ; 2 o f b o o l e a n

    i n i t i a l l y ( 8 r c 0 r < k ; 1 0 c < k ; 1 X r c = ? Y r c 6= f a l s e )

    p r o c e s s p = k d i s t i n c t p r o c e s s e s r a n g i n g o v e r 0 N ; 1 =

    p r i v a t e v a r i a b l e n a m e 0 k ( k + 1 ) = 2 ; 1

    s t o p b o o l e a n

    i j 0 k ; 1

    i n i t i a l l y i = 0 j = 0 ^ : s t o p

    w h i l e i + j < k ; 1 ^ : s t o p d o = M o v e d o w n o r a c r o s s g r i d u n t i l s t o p p i n g o r r e a c h i n g e d g e =

    0 X i j = p

    1 i f Y i j t h e n j = j + 1 = M o v e r i g h t =

    e l s e

    2 Y i j = t r u e

    3 i f X i j = p t h e n s t o p = t r u e e l s e i = i + 1 = S t o p o r m o v e d o w n =

    o d

    4 n a m e = i k ; i ( i ; 1 ) = 2 + j = C a l c u l a t e n a m e b a s e d o n p o s i t i o n i n g r i d =

    5 h a l t = P r e s e r v e s p @ 5 h a s n o e e c t =

    F i g u r e 4 : O n e - t i m e r e n a m i n g u s i n g a g r i d o f b u i l d i n g b l o c k s .

    U s i n g t h e a l g o r i t h m d e s c r i b e d i n t h i s s e c t i o n , k p r o c e s s e s c a n r e d u c e t h e s i z e o f t h e i r n a m e s p a c e f r o m

    N t o k ( k + 2 ) = 2 w i t h t i m e c o m p l e x i t y ( k ) . U s i n g t h e a l g o r i t h m r e c e n t l y p r e s e n t e d b y B o r o w s k y a n d G a f n i

    i n 5 ] , k p r o c e s s e s c a n r e d u c e t h e s i z e o f t h e i r n a m e s p a c e f r o m N t o 2 k ; 1 w i t h t i m e c o m p l e x i t y ( N k

    2

    )

    C o m b i n i n g t h e t w o a l g o r i t h m s , k p r o c e s s e s c a n r e d u c e t h e s i z e o f t h e i r n a m e s p a c e f r o m N t o 2 k ; 1 w i t h

    t i m e c o m p l e x i t y ( k ) + ( ( k ( k + 1 ) = 2 ) k

    2

    ) = ( k

    4

    ) . T h u s , w e h a v e t h e f o l l o w i n g r e s u l t . B y r e s u l t s o f H e r l i h y

    a n d S h a v i t 7 ] , t h i s a l g o r i t h m i s o p t i m a l w i t h r e s p e c t t o t h e s i z e o f t h e n a m e s p a c e .

    T h e o r e m 2 : U s i n g r e a d a n d w r i t e , w a i t - f r e e , o n e - t i m e ( 2 k ; 1 ) - r e n a m i n g c a n b e i m p l e m e n t e d s o t h a t t h e

    w o r s t - c a s e t i m e c o m p l e x i t y o f a c q u i r i n g a n a m e o n c e i s ( k

    4

    ) 2

    4 L o n g - L i v e d R e n a m i n g u s i n g R e a d s a n d W r i t e s

    I n t h i s s e c t i o n , w e p r e s e n t a l o n g - l i v e d r e n a m i n g a l g o r i t h m t h a t u s e s o n l y a t o m i c r e a d a n d w r i t e o p e r a t i o n s .

    T h i s a l g o r i t h m i s b a s e d o n t h e g r i d a l g o r i t h m p r e s e n t e d i n t h e p r e v i o u s s e c t i o n . T o e n a b l e p r o c e s s e s t o

    r e l e a s e n a m e s a s w e l l a s a c q u i r e n a m e s , w e m o d i f y t h e o n e - t i m e b u i l d i n g b l o c k . T h e m o d i c a t i o n a l l o w s a

    p r o c e s s t o \ r e s e t " a b u i l d i n g b l o c k t h a t i t h a s p r e v i o u s l y a c c e s s e d . T h i s a l g o r i t h m y i e l d s a n a m e s p a c e o f

    s i z e k ( k + 1 ) = 2 a n d h a s t i m e c o m p l e x i t y ( N k ) . W e n o w g i v e a n i n f o r m a l d e s c r i p t i o n o f t h e a l g o r i t h m . A

    c o r r e c t n e s s p r o o f a p p e a r s i n A p p e n d i x B .

    4 . 1 U s i n g t h e L o n g - L i v e d B u i l d i n g B l o c k f o r L o n g - L i v e d R e n a m i n g

    O u r l o n g - l i v e d r e n a m i n g a l g o r i t h m b a s e d o n r e a d s a n d w r i t e s i s s h o w n i n F i g u r e 5 . A s i n t h e o n e - t i m e

    a l g o r i t h m p r e s e n t e d i n t h e p r e v i o u s s e c t i o n , a p r o c e s s a c q u i r e s a n a m e b y s t a r t i n g a t t h e t o p l e f t c o r n e r o f a

    g r i d o f b u i l d i n g b l o c k s , a n d b y m o v i n g t h r o u g h t h e g r i d a c c o r d i n g t o t h e v a l u e r e c e i v e d f r o m e a c h b u i l d i n g

    b l o c k . T h e b u i l d i n g b l o c k s a r e s i m i l a r t o t h o s e d e s c r i b e d i n t h e p r e v i o u s s e c t i o n , e x c e p t t h a t t h e y c a n b e

    \ r e s e t " ( s t a t e m e n t 6 ) a f t e r b e i n g a c c e s s e d ( s t a t e m e n t s 2 t h r o u g h 5 ) . T h e r e a r e t w o s i g n i c a n t d i e r e n c e s

    b e t w e e n t h i s a l g o r i t h m a n d t h e o n e - t i m e r e n a m i n g a l g o r i t h m .

    7

  • 8/14/2019 Moir Anderson Sc495

    8/31

    s h a r e d v a r i a b l e X a r r a y 0 k ; 2 0 k ; 2 o f f ? g f 0 N ; 1 g

    Y a r r a y 0 k ; 2 0 k ; 2 o f a r r a y 0 N ; 1 o f b o o l e a n

    i n i t i a l l y ( 8 r c p 0 r < k ; 1 0 c < k ; 1 0 p < N X r c = ? Y r c p = f a l s e )

    p r o c e s s p = 0 p < N =

    p r i v a t e v a r i a b l e n a m e 0 k ( k + 1 ) = 2 ; 1

    m o v e f s t o p r i g h t d o w n g

    i j 0 k ; 1

    i n i t i a l l y i = 0 j = 0 m o v e = d o w n

    w h i l e t r u e d o

    0 R e m a i n d e r S e c t i o n

    1 i j m o v e = 0 0 d o w n = S t a r t a t t o p l e f t b u i l d i n g b l o c k i n g r i d =

    w h i l e i + j < k ; 1 m o v e 6= s t o p d o = M o v e d o w n o r a c r o s s g r i d u n t i l s t o p p i n g o r r e a c h i n g e d g e =

    2 X i j h m o v e = p 0 s t o p = W i l l s t o p u n l e s s m o v e l a t e r b e c o m e s r i g h t o r d o w n =

    w h i l e h < N m o v e 6= r i g h t d o

    3 i f Y i j h t h e n m o v e = r i g h t e l s e h = h + 1

    o d

    4 i f m o v e 6= r i g h t t h e n

    Y i j p = t r u e

    5 i f X i j 6= p t h e n m o v e = d o w n e l s e m o v e = s t o p

    6 i f m o v e 6= s t o p t h e n

    Y i j p = f a l s e = R e s e t b l o c k i f w e d i d n ' t s t o p a t i t =

    i f m o v e = d o w n t h e n i = i + 1 e l s e j = j + 1 = M o v e a c c o r d i n g t o m o v e =

    o d

    7 n a m e = i k ; i ( i ; 1 ) = 2 + j = C a l c u l a t e n a m e b a s e d o n p o s i t i o n i n g r i d =

    W o r k i n g S e c t i o n

    8 i f i + j < k ; 1 t h e n = I f w e s t o p p e d o n a b u i l d i n g b l o c k . . . =

    Y i j p = f a l s e = . . . t h e n r e s e t t h a t b u i l d i n g b l o c k =

    o d

    F i g u r e 5 : L o n g - l i v e d r e n a m i n g w i t h ( k

    2

    ) n a m e s p a c e a n d ( N k ) t i m e c o m p l e x i t y .

    F i r s t l y , t h e s i n g l e Y - b i t u s e d i n t h e o n e - t i m e a l g o r i t h m i s r e p l a c e d b y N Y - b i t s | o n e f o r e a c h p r o c e s s .

    I n s t e a d o f s e t t i n g a c o m m o n Y - b i t , e a c h p r o c e s s p s e t s a d i s t i n c t b i t Y p ] ( s t a t e m e n t 4 ) . T h i s m o d i c a t i o n

    a l l o w s a p r o c e s s t o r e s e t t h e b u i l d i n g b l o c k b y c l e a r i n g i t s Y - b i t . A p r o c e s s r e s e t s a b u i l d i n g b l o c k i t h a s

    a c c e s s e d b e f o r e p r o c e e d i n g t o t h e n e x t b u i l d i n g b l o c k i n t h e g r i d ( s t a t e m e n t 6 ) , o r w h e n r e l e a s i n g t h e n a m e

    a s s o c i a t e d w i t h t h a t b u i l d i n g b l o c k ( s t a t e m e n t 8 ) . T h e b u i l d i n g b l o c k s a r e r e s e t t o a l l o w p r o c e s s e s t o r e u s e

    t h e g r i d t o a c q u i r e n a m e s r e p e a t e d l y . ( I t m a y s e e m m o r e i n t u i t i v e t o r e s e t a l l b u i l d i n g b l o c k s a c c e s s e d w h e n

    r e l e a s i n g a n a m e . I n f a c t , t h i s d o e s n o t a e c t c o r r e c t n e s s , a n d r e s e t t i n g e a c h b u i l d i n g b l o c k b e f o r e a c c e s s i n g

    t h e n e x t a v o i d s t h e n e e d f o r a d a t a s t r u c t u r e t o r e c o r d w h i c h b u i l d i n g b l o c k s w e r e a c c e s s e d . )

    T o s e e w h y N Y - b i t s a r e u s e d , o b s e r v e t h a t i n t h e o n e - t i m e b u i l d i n g b l o c k , t h e Y - v a r i a b l e i s n e v e r r e s e t ,

    s o u s i n g a s i n g l e b i t s u c e s . H o w e v e r , i f o n l y o n e Y - b i t i s u s e d i n t h e l o n g - l i v e d a l g o r i t h m , a p r o c e s s m i g h t

    r e s e t Y i m m e d i a t e l y a f t e r a n o t h e r p r o c e s s , s a y p , s e t s Y . B e c a u s e t h e v a l u e p a s s i g n e d t o Y i s o v e r w r i t t e n ,

    a n o t h e r p r o c e s s q m a y s u b s e q u e n t l y a c c e s s t h e b u i l d i n g b l o c k a n d f a i l t o d e t e c t t h a t p h a s a c c e s s e d t h e

    b u i l d i n g b l o c k . I n t h i s c a s e , p a n d q m a y b o t h r e c e i v e a v a l u e o f s t o p f r o m t h e s a m e b u i l d i n g b l o c k .

    T h e s e c o n d d i e r e n c e b e t w e e n t h e o n e - t i m e a n d l o n g - l i v e d b u i l d i n g b l o c k s i s t h a t t h e y d i e r i n t i m e

    c o m p l e x i t y . I n s t e a d o f r e a d i n g a s i n g l e Y - v a r i a b l e , e a c h p r o c e s s n o w r e a d s a l l N Y - b i t s . T h i s r e s u l t s i n

    ( N ) t i m e c o m p l e x i t y f o r a c c e s s i n g t h e l o n g - l i v e d b u i l d i n g b l o c k . I t m a y s e e m t h a t a l l N Y - b i t s s h o u l d b e

    8

  • 8/14/2019 Moir Anderson Sc495

    9/31

    r e a d i n a n a t o m i c \ s n a p s h o t " b e c a u s e , f o r e x a m p l e , p ' s w r i t e t o Y p ] m i g h t o c c u r c o n c u r r e n t l y w i t h q ' s s c a n

    o f t h e Y - b i t s . I n f a c t , t h i s i s u n n e c e s s a r y , b e c a u s e t h e f a c t t h a t t h e s e o p e r a t i o n s a r e c o n c u r r e n t i s s u c i e n t

    t o e n s u r e t h a t e i t h e r p o r q w i l l n o t r e c e i v e a v a l u e o f s t o p f r o m t h e b u i l d i n g b l o c k .

    I n A p p e n d i x B , w e p r o v e t h a t , f o r d i s t i n c t p r o c e s s e s p a n d q i f p @ 8 q @ 8 h o l d s , t h e n p a n d q h o l d

    d i s t i n c t n a m e s f r o m f 0 : : : k ( k + 1 ) = 2 ; 1 g ( s e e ( I 2 8 ) a n d ( I 2 9 ) ) . W e a l s o p r o v e t h a t a p r o c e s s p e r f o r m s a t

    m o s t ( N + 4 ) ( k ; 1 ) s h a r e d v a r i a b l e a c c e s s e s i n a c q u i r i n g a n a m e . R e l e a s i n g a n a m e r e q u i r e s a t m o s t o n e

    s h a r e d v a r i a b l e a c c e s s . T h u s , w e h a v e t h e f o l l o w i n g r e s u l t .

    T h e o r e m 3 : U s i n g r e a d a n d w r i t e , w a i t - f r e e , l o n g - l i v e d ( k ( k + 1 ) = 2 ) - r e n a m i n g c a n b e i m p l e m e n t e d s o t h a t

    t h e w o r s t - c a s e t i m e c o m p l e x i t y o f a c q u i r i n g a n d r e l e a s i n g a n a m e o n c e i s ( N + 4 ) ( k ; 1 ) + 1 = ( N k ) 2

    5 L o n g - L i v e d R e n a m i n g u s i n g R e a d - M o d i f y - W r i t e s

    I n t h i s s e c t i o n , w e p r e s e n t t h r e e w a i t - f r e e , l o n g - l i v e d r e n a m i n g a l g o r i t h m s a n d o n e l o c k - f r e e , l o n g - l i v e d a l g o -

    r i t h m . B y u s i n g r e a d - m o d i f y - w r i t e o p e r a t i o n s , t h e s e a l g o r i t h m s s i g n i c a n t l y i m p r o v e u p o n t h e p e r f o r m a n c e

    o f t h e a l g o r i t h m s i n t h e p r e v i o u s s e c t i o n . F u r t h e r m o r e , t h e s e a l g o r i t h m s y i e l d a n a m e s p a c e o f s i z e k , w h i c h

    i s c l e a r l y o p t i m a l ( t h e l o w e r b o u n d r e s u l t s o f H e r l i h y a n d S h a v i t 7 ] d o n o t a p p l y t o a l g o r i t h m s t h a t e m p l o y

    r e a d - m o d i f y - w r i t e o p e r a t i o n s ) .

    T h e r s t a l g o r i t h m u s e s s e t r s t z e r o a n d c l r b i t t o a c c e s s s h a r e d , b - b i t v a r i a b l e s a n d h a s t i m e c o m p l e x i t y

    ( k = b ) . A s d i s c u s s e d i n S e c t i o n 1 , t h e s e o p e r a t i o n s c a n b e i m p l e m e n t e d , f o r e x a m p l e , u s i n g o p e r a t i o n s

    a v a i l a b l e o n t h e B B N T C 2 0 0 0 4 ] . T h e s e c o n d a l g o r i t h m i n t h i s s e c t i o n h a s t i m e c o m p l e x i t y ( l o g k ) |

    a s i g n i c a n t i m p r o v e m e n t o v e r t h e r s t a l g o r i t h m . T o a c h i e v e t h i s i m p r o v e m e n t , t h i s a l g o r i t h m u s e s t h e

    b o u n d e d d e c r e m e n t o p e r a t i o n . W e t h e n d e s c r i b e h o w t h e t e c h n i q u e s f r o m t h e s e t w o a l g o r i t h m s c a n b e

    c o m b i n e d t o o b t a i n a n a l g o r i t h m w h o s e t i m e c o m p l e x i t y i s b e t t e r t h a n t h a t o f e i t h e r a l g o r i t h m .

    W e d o n o t k n o w o f a n y s y s t e m s t h a t p r o v i d e b o u n d e d d e c r e m e n t a s a p r i m i t i v e o p e r a t i o n . H o w e v e r , a t

    t h e e n d o f t h i s s e c t i o n , w e d i s c u s s h o w t h e b o u n d e d d e c r e m e n t o p e r a t i o n c a n b e a p p r o x i m a t e d i n a l o c k - f r e e

    m a n n e r u s i n g t h e c o m m o n l y - a v a i l a b l e f e t c h a n d a d d o p e r a t i o n . W e s h o w h o w t h i s a p p r o x i m a t i o n c a n b e

    u s e d t o p r o v i d e a l o c k - f r e e a l g o r i t h m f o r l o n g - l i v e d k - r e n a m i n g .

    5 . 1 L o n g - L i v e d R e n a m i n g u s i n g s e t r s t z e r o a n d c l r b i t

    O u r r s t l o n g - l i v e d k - r e n a m i n g a l g o r i t h m e m p l o y s t h e s e t r s t z e r o a n d c l r b i t o p e r a t i o n s . T h e a l g o r i t h m

    i s s h o w n i n F i g u r e 6 . F o r c l a r i t y , w e h a v e e x p l i c i t l y u s e d t h e d e n i t i o n s o f s e t r s t z e r o ( s t a t e m e n t 1 ) a n d

    c l r b i t ( s t a t e m e n t 3 ) . I n o r d e r t o a c q u i r e a n a m e , a p r o c e s s t e s t s e a c h n a m e i n o r d e r . U s i n g t h e s e t r s t z e r o

    o p e r a t i o n o n b - b i t v a r i a b l e s , u p t o b n a m e s c a n b e t e s t e d i n o n e a t o m i c s h a r e d v a r i a b l e a c c e s s . I f k b

    t h i s r e s u l t s i n a l o n g - l i v e d r e n a m i n g a l g o r i t h m t h a t a c q u i r e s a n a m e w i t h j u s t o n e s h a r e d v a r i a b l e a c c e s s . I f

    k > b , t h e n \ s e g m e n t s " o f s i z e b o f t h e n a m e s p a c e a r e t e s t e d i n e a c h a c c e s s . T o r e l e a s e a n a m e , a p r o c e s s

    c l e a r s t h e b i t t h a t w a s s e t b y t h a t p r o c e s s w h e n t h e n a m e w a s a c q u i r e d . A n e x a m p l e i s s h o w n i n F i g u r e 7

    f o r b = 4 a n d k = 1 0 . I n t h i s g u r e , p r o c e s s p r e l e a s e s n a m e 1 b y e x e c u t i n g c l r b i t ( X 0 1 ) a n d p r o c e s s q

    a c q u i r e s n a m e 5 b y e x e c u t i n g s e t r s t z e r o ( X 1 ] ) .

    B e c a u s e e a c h p r o c e s s t e s t s t h e a v a i l a b l e n a m e s i n s e g m e n t s , a n d b e c a u s e p r o c e s s e s m a y r e l e a s e a n d

    a c q u i r e n a m e s c o n c u r r e n t l y , i t m a y s e e m p o s s i b l e f o r a p r o c e s s t o r e a c h t h e l a s t s e g m e n t w h e n n o n e o f t h e

    n a m e s i n t h a t s e g m e n t a r e a v a i l a b l e . I n A p p e n d i x C , w e s h o w t h a t t h i s i s i n f a c t i m p o s s i b l e a n d t h a t e a c h

    p r o c e s s a c q u i r e s a d i s t i n c t n a m e f r o m f 0 : : : k ; 1 g a f t e r a t m o s t d k = b e s h a r e d v a r i a b l e a c c e s s e s ( s e e ( I 3 9 )

    a n d ( I 4 0 ) ) . R e l e a s i n g a n a m e r e q u i r e s o n e s h a r e d v a r i a b l e a c c e s s . T h u s , t h e a l g o r i t h m s h o w n i n F i g u r e 6

    y i e l d s t h e f o l l o w i n g r e s u l t .

    T h e o r e m 4 : U s i n g s e t r s t z e r o a n d c l r b i t o n b - b i t v a r i a b l e s , w a i t - f r e e , l o n g - l i v e d k - r e n a m i n g c a n b e

    i m p l e m e n t e d s o t h a t t h e w o r s t - c a s e t i m e c o m p l e x i t y o f a c q u i r i n g a n d r e l e a s i n g a n a m e o n c e i s d k = b e + 1 2

    9

  • 8/14/2019 Moir Anderson Sc495

    10/31

    s h a r e d v a r i a b l e X a r r a y 0 b k = b c o f a r r a y 0 b ; 1 o f b o o l e a n = b - b i t \ s e g m e n t s " o f t h e n a m e s p a c e =

    i n i t i a l l y ( 8 i j 0 i b k = b c 0 j < b X i j = f a l s e )

    p r o c e s s p = 0 p < N =

    p r i v a t e v a r i a b l e h 0 b k = b c + 1 v 0 b n a m e 0 k ; 1

    i n i t i a l l y h = 0

    w h i l e t r u e d o

    0 R e m a i n d e r S e c t i o n

    h v = 0 b = I n i t i a l i z e h a n d v a f t e r r e m a i n d e r s e c t i o n =

    w h i l e v = b d o = L o o p u n t i l a b i t i s s e t =

    1 i f ( 9 n 0 n < b : X h n ) t h e n = s e t r s t z e r o o p e r a t i o n , a s d e n e d i n S e c t i o n 2 =

    m : = ( m i n n 0 n < b : X h n ) X h m v = t r u e m

    e l s e

    v = b

    i f v = b t h e n h = h + 1

    o d

    2 n a m e = b h + v = C a l c u l a t e n a m e =

    W o r k i n g S e c t i o n

    3 X h v = f a l s e = C l e a r t h e b i t t h a t w a s s e t =

    o d

    F i g u r e 6 : L o n g - l i v e d k - r e n a m i n g u s i n g s e t r s t z e r o a n d c l e a r b i t

    A s d i s c u s s e d i n S e c t i o n 1 , w h e n b = 1 , t h e s e t r s t z e r o a n d c l r b i t o p e r a t i o n s a r e e q u i v a l e n t t o t h e

    t e s t a n d s e t a n d w r i t e o p e r a t i o n s , r e s p e c t i v e l y . T h u s , w e h a v e t h e f o l l o w i n g .

    C o r o l l a r y : U s i n g t e s t a n d s e t a n d w r i t e , w a i t - f r e e , l o n g - l i v e d k - r e n a m i n g c a n b e i m p l e m e n t e d w i t h t i m e

    c o m p l e x i t y k + 1 2

    5 . 2 L o n g - L i v e d R e n a m i n g u s i n g b o u n d e d d e c r e m e n t a n d f e t c h a n d a d d

    I n t h i s s e c t i o n , w e p r e s e n t a l o n g - l i v e d k - r e n a m i n g a l g o r i t h m t h a t e m p l o y s t h e b o u n d e d d e c r e m e n t a n d

    f e t c h a n d a d d o p e r a t i o n s . I n t h i s a l g o r i t h m , s h o w n i n F i g u r e 8 , t h e b o u n d e d d e c r e m e n t o p e r a t i o n i s u s e d t o

    s e p a r a t e p r o c e s s e s i n t o t w o g r o u p s l e f t a n d r i g h t . T h e r i g h t g r o u p c o n t a i n s a t m o s t d k = 2 e p r o c e s s e s a n d t h e

    l e f t g r o u p c o n t a i n s a t m o s t b k = 2 c p r o c e s s e s . T h i s i s a c h i e v e d b y i n i t i a l i z i n g a s h a r e d v a r i a b l e X t o d k = 2 e

    a n d h a v i n g e a c h p r o c e s s p e r f o r m a b o u n d e d d e c r e m e n t o p e r a t i o n o n X . P r o c e s s e s t h a t r e c e i v e p o s i t i v e r e t u r n

    v a l u e s j o i n t h e r i g h t g r o u p , a n d p r o c e s s e s t h a t r e c e i v e z e r o j o i n t h e l e f t g r o u p . T o l e a v e t h e r i g h t g r o u p , a

    p r o c e s s i n c r e m e n t s X . T o l e a v e t h e l e f t g r o u p , n o s h a r e d v a r i a b l e s a r e u p d a t e d .

    I t m i g h t s e e m p o s s i b l e t o i m p l e m e n t t h i s \ s p l i t t i n g " m e c h a n i s m b y h a v i n g a p r o c e s s j o i n t h e l e f t g r o u p

    i i t r e c e i v e s a n o n p o s i t i v e r e t u r n v a l u e f r o m a n o r m a l f e t c h a n d a d d ( X ; 1 ) o p e r a t i o n . H o w e v e r , b e c a u s e

    p r o c e s s e s m u s t b e a b l e t o r e p e a t e d l y j o i n a n d l e a v e t h e g r o u p s , t h e n o r m a l f e t c h a n d a d d o p e r a t i o n i s n o t

    s u i t a b l e f o r t h i s \ s p l i t t i n g " m e c h a n i s m . I f X i s d e c r e m e n t e d b e l o w z e r o , t h e n i t i s p o s s i b l e f o r t o o m a n y

    p r o c e s s e s t o b e i n t h e l e f t g r o u p a t o n c e . T o s e e t h i s , s u p p o s e t h a t a l l k p r o c e s s e s d e c r e m e n t X . T h u s ,

    d k = 2 e p r o c e s s e s r e c e i v e p o s i t i v e r e t u r n v a l u e s , a n d t h e r e f o r e j o i n t h e r i g h t g r o u p , a n d b k = 2 c p r o c e s s e s r e c e i v e

    n o n - p o s i t i v e r e t u r n v a l u e s , a n d t h e r e f o r e j o i n t h e l e f t g r o u p . N o w , X = ; b k = 2 c . I f a p r o c e s s l e a v e s t h e

    r i g h t g r o u p b y i n c r e m e n t i n g X , a n d t h e n d e c r e m e n t s X a s t h e r e s u l t o f a s u b s e q u e n t a t t e m p t t o a c q u i r e a

    n a m e , t h e n t h a t p r o c e s s r e c e i v e s a n o n - p o s i t i v e r e t u r n v a l u e , a n d t h u s j o i n s t h e l e f t g r o u p . R e p e a t i n g t h i s

    f o r e a c h p r o c e s s i n t h e r i g h t g r o u p , i t i s p o s s i b l e f o r a l l p r o c e s s e s t o b e i n t h e l e f t g r o u p s i m u l t a n e o u s l y . T h e

    b o u n d e d d e c r e m e n t o p e r a t i o n p r e v e n t s t h i s b y e n s u r i n g t h a t X d o e s n o t b e c o m e n e g a t i v e .

    T h e a l g o r i t h m e m p l o y s a n i n s t a n c e o f l o n g - l i v e d d k = 2 e - r e n a m i n g f o r t h e r i g h t g r o u p , a n d a n i n s t a n c e o f

    1 0

  • 8/14/2019 Moir Anderson Sc495

    11/31

  • 8/14/2019 Moir Anderson Sc495

    12/31

    s h a r e d v a r i a b l e X 0 d k = 2 e = C o u n t e r o f n a m e s a v a i l a b l e o n r i g h t =

    i n i t i a l l y X = d k = 2 e

    p r o c e s s p = 0 p < N =

    p r i v a t e v a r i a b l e s i d e f l e f t r i g h t g

    w h i l e t r u e d o

    0 R e m a i n d e r S e c t i o n

    1 i f b o u n d e d d e c r e m e n t ( X ) > 0 t h e n = E n s u r e a t m o s t d k = 2 e a c c e s s r i g h t a n d a t m o s t b k = 2 c a c c e s s l e f t =

    2 s i d e n a m e = r i g h t G e t n a m e r i g h t ( ) = G e t n a m e f r o m r i g h t i n s t a n c e =

    e l s e

    3 s i d e n a m e = l e f t d k = 2 e + G e t n a m e l e f t ( ) = G e t n a m e f r o m l e f t i n s t a n c e =

    W o r k i n g S e c t i o n

    4 i f s i d e = r i g h t t h e n

    5 P u t n a m e r i g h t ( n a m e ) = R e t u r n n a m e t o r i g h t i n s t a n c e =

    6 f e t c h a n d a d d ( X 1 ) = I n c r e m e n t c o u n t e r a g a i n =

    e l s e

    7 P u t n a m e l e f t ( n a m e ; d k = 2 e ) = R e t u r n n a m e t o l e f t i n s t a n c e =

    o d

    F i g u r e 8 : k - r e n a m i n g u s i n g b o u n d e d d e c r e m e n t G e t n a m e l e f t a n d P u t n a m e l e f t a r e i n d u c t i v e l y a s s u m e d t o i m p l e -

    m e n t l o n g - l i v e d b k = 2 c - r e n a m i n g . S i m i l a r l y , G e t n a m e r i g h t a n d P u t n a m e r i g h t a r e i n d u c t i v e l y a s s u m e d t o i m p l e m e n t

    l o n g - l i v e d d k = 2 e - r e n a m i n g .

    5 . 3 L o c k - F r e e , L o n g - L i v e d k - R e n a m i n g u s i n g f e t c h a n d a d d

    T h e k - r e n a m i n g a l g o r i t h m p r e s e n t e d i n F i g u r e 8 i s t h e b a s i s o f o u r f a s t e s t w a i t - f r e e k - r e n a m i n g s o l u t i o n s ,

    a s s h o w n b y T h e o r e m s 5 a n d 6 . U n f o r t u n a t e l y , t h e b o u n d e d d e c r e m e n t o p e r a t i o n e m p l o y e d b y t h a t a l -

    g o r i t h m i s n o t w i d e l y a v a i l a b l e . W h i l e t h e b o u n d e d d e c r e m e n t o p e r a t i o n i s s i m i l a r t o t h e w e l l - k n o w n

    f e t c h a n d a d d o p e r a t i o n , w e h a v e b e e n u n a b l e t o d e s i g n a n e c i e n t w a i t - f r e e i m p l e m e n t a t i o n o f t h e f o r -

    m e r u s i n g t h e l a t t e r . W e h a v e , h o w e v e r , d e s i g n e d a l o c k - f r e e k - r e n a m i n g a l g o r i t h m t h a t i s b a s e d o n t h e

    i d e a o f b o u n d e d d e c r e m e n t . T h e a l g o r i t h m i s p r e s e n t e d i n F i g u r e 9 . T h e f e t c h a n d a d d o p e r a t i o n i s u s e d t o

    a p p r o x i m a t e t h e b o u n d e d d e c r e m e n t o p e r a t i o n i n s u c h a w a y t h a t i t e n s u r e s t h a t a t m o s t d k = 2 e p r o c e s s e s

    a c c e s s t h e r i g h t i n s t a n c e o f d k = 2 e - r e n a m i n g , a n d s i m i l a r l y f o r t h e l e f t i n s t a n c e .

    R o u g h l y s p e a k i n g , t h i s s p l i t i s a c h i e v e d b y h a v i n g p r o c e s s e s t h a t o b t a i n p o s i t i v e v a l u e s f r o m X g o r i g h t ,

    a n d p r o c e s s e s t h a t o b t a i n n o n - p o s i t i v e v a l u e s g o l e f t ( s e e s t a t e m e n t s 1 a n d 2 i n F i g u r e 9 ) . H o w e v e r , a

    p r o c e s s , s a y p , t h a t d e c r e m e n t s t h e c o u n t e r X b e l o w z e r o \ c o m p e n s a t e s " b y i n c r e m e n t i n g X a g a i n b e f o r e

    p r o c e e d i n g l e f t . I f p d e t e c t s t h a t X b e c o m e s p o s i t i v e a g a i n b e f o r e t h i s c o m p e n s a t i o n i s m a d e , t h e n i t i s

    p o s s i b l e t h a t s o m e o t h e r p r o c e s s h a s i n c r e m e n t e d X a n d j o i n e d t h e l e f t g r o u p . I n t h i s c a s e , t h e r e i s a r i s k

    t h a t p r o c e s s p s h o u l d i n f a c t g o r i g h t , r a t h e r t h a n l e f t . I n t h i s c a s e , p r o c e s s p r e s t a r t s t h e l o o p .

    T h e a l g o r i t h m i s l o c k - f r e e b e c a u s e i n o r d e r f o r a p r o c e s s t o r e p e a t t h e l o o p a t s t a t e m e n t s 1 a n d 2 , s o m e

    o t h e r p r o c e s s m u s t m o d i f y X b e t w e e n t h e e x e c u t i o n o f s t a t e m e n t s 1 a n d 2 . I n A p p e n d i x E , w e s h o w t h a t i f

    t h i s h a p p e n s r e p e a t e d l y , t h e n e v e n t u a l l y s o m e p r o c e s s m a k e s p r o g r e s s . T h u s , w e h a v e t h e f o l l o w i n g r e s u l t .

    T h e o r e m 7 : U s i n g b - b i t v a r i a b l e s a n d f e t c h a n d a d d , l o c k - f r e e , l o n g - l i v e d k - r e n a m i n g c a n b e i m p l e m e n t e d

    s o t h a t t h e w o r s t - c a s e , c o n t e n t i o n - f r e e t i m e c o m p l e x i t y o f a c q u i r i n g a n d r e l e a s i n g a n a m e o n c e i s 2 d l o g

    2

    k e

    f o r k 2 ( 2

    b

    ; 1 ) 2

    1 2

  • 8/14/2019 Moir Anderson Sc495

    13/31

    s h a r e d v a r i a b l e X ; b k = 2 c d k = 2 e = C o u n t e r o f n a m e s a v a i l a b l e o n r i g h t =

    i n i t i a l l y X = d k = 2 e

    p r o c e s s p = 0 p < N =

    p r i v a t e v a r i a b l e s i d e f l e f t r i g h t n o n e g

    w h i l e t r u e d o

    0 R e m a i n d e r S e c t i o n

    s i d e = n o n e

    w h i l e s i d e = n o n e d o

    1 i f f e t c h a n d a d d ( X ; 1 ) > 0 t h e n s i d e = r i g h t

    2 e l s e i f f e t c h a n d a d d ( X 1 )

  • 8/14/2019 Moir Anderson Sc495

    14/31

    O u r m o s t e c i e n t w a i t - f r e e , l o n g - l i v e d r e n a m i n g a l g o r i t h m u s e s a b o u n d e d d e c r e m e n t o p e r a t i o n . A l t h o u g h

    t h i s o p e r a t i o n i s s i m i l a r t o t h e s t a n d a r d f e t c h a n d a d d o p e r a t i o n , w e h a v e b e e n u n a b l e t o d e s i g n a n e c i e n t

    w a i t - f r e e i m p l e m e n t a t i o n o f t h e f o r m e r u s i n g t h e l a t t e r . W e h a v e , h o w e v e r , d e s i g n e d a n e c i e n t l o c k - f r e e

    i m p l e m e n t a t i o n o f k - r e n a m i n g b a s e d o n t h i s i d e a . I n t h i s i m p l e m e n t a t i o n , a p r o c e s s c a n o n l y b e d e l a y e d b y

    a v e r y u n l i k e l y s e q u e n c e o f e v e n t s . W e b e l i e v e t h i s i m p l e m e n t a t i o n w i l l p e r f o r m w e l l i n p r a c t i c e . I t r e m a i n s

    t o b e s e e n w h e t h e r f e t c h a n d a d d c a n b e u s e d t o i m p l e m e n t w a i t - f r e e , l o n g - l i v e d r e n a m i n g w i t h s u b - l i n e a r

    t i m e c o m p l e x i t y .

    A c k n o w l e d g e m e n t : W e w o u l d l i k e t o t h a n k G a d i T a u b e n f e l d a n d R a j e e v A l u r f o r h e l p f u l d i s c u s s i o n s . W e a r e a l s o

    g r a t e f u l t o t h e a n o n y m o u s r e f e r e e s f o r t h e i r e o r t s t o i m p r o v e t h e p r e s e n t a t i o n o f t h i s p a p e r .

    R e f e r e n c e s

    1 ] J . A n d e r s o n a n d M . M o i r , \ U s i n g k - E x c l u s i o n t o I m p l e m e n t R e s i l i e n t , S c a l a b l e S h a r e d O b j e c t s " , P r o -

    c e e d i n g s o f t h e 1 3 t h A n n u a l A C M S y m p o s i u m o n P r i n c i p l e s o f D i s t r i b u t e d C o m p u t i n g , A u g u s t 1 9 9 4 ,

    p p . 1 4 1 - 1 5 0 .

    2 ] H . A t t i y a , A . B a r - N o y , D . D o l e v , D . K o l l e r , D . P e l e g , a n d R . R e i s c h u k , \ A c h i e v a b l e C a s e s i n a n A s y n -

    c h r o n o u s E n v i r o n m e n t " , P r o c e e d i n g s o f t h e 2 8 t h A n n u a l I E E E S y m p o s i u m o n F o u n d a t i o n s o f C o m p u t e r

    S c i e n c e , O c t o b e r 1 9 8 7 , p p . 3 3 7 - 3 4 6 .

    3 ] A . B a r - N o y a n d D . D o l e v , \ S h a r e d M e m o r y v e r s u s M e s s a g e - P a s s i n g i n a n A s y n c h r o n o u s D i s t r i b u t e d

    E n v i r o n m e n t " , P r o c e e d i n g s o f t h e 8 t h A n n u a l A C M S y m p o s i u m o n P r i n c i p l e s o f D i s t r i b u t e d C o m p u t i n g

    A u g u s t 1 9 8 9 , p p . 3 0 7 - 3 1 8 .

    4 ] B B N A d v a n c e d C o m p u t e r s , I n s i d e t h e T C 2 0 0 0 C o m p u t e r , F e b r u a r y , 1 9 9 0 .

    5 ] E . B o r o w s k y a n d E . G a f n i , \ I m m e d i a t e A t o m i c S n a p s h o t s a n d F a s t R e n a m i n g " , P r o c e e d i n g s o f t h e 1 2 t h

    A n n u a l A C M S y m p o s i u m o n P r i n c i p l e s o f D i s t r i b u t e d C o m p u t i n g , A u g u s t 1 9 9 3 , p p . 4 1 - 5 0 .

    6 ] C . A . R . H o a r e , \ A n A x i o m a t i c B a s i s f o r C o m p u t e r P r o g r a m m i n g " , C o m m u n i c a t i o n s o f t h e A C M 1 2

    O c t o b e r 1 9 6 9 , p p . 5 7 6 - 5 8 0 , 5 8 3 .

    7 ] M . H e r l i h y a n d N . S h a v i t , \ T h e A s y n c h r o n o u s C o m p u t a b i l i t y T h e o r e m f o r t - R e s i l i e n t T a s k s " , P r o c e e d -

    i n g s o f t h e 2 5 t h A C M S y m p o s i u m o n T h e o r y o f C o m p u t i n g , 1 9 9 3 , p p . 1 1 1 - 1 2 0 .

    8 ] L . L a m p o r t , \ A F a s t M u t u a l E x c l u s i o n A l g o r i t h m " , A C M T r a n s a c t i o n s o n C o m p u t e r S y s t e m s , V o l . 5 ,

    N o . 1 , F e b r u a r y 1 9 8 7 , p p . 1 - 1 1 .

    9 ] M . M o i r a n d J . A n d e r s o n , \ F a s t , L o n g - L i v e d R e n a m i n g " , P r o c e e d i n g s o f t h e 8 t h I n t e r n a t i o n a l W o r k s h o p

    o n D i s t r i b u t e d A l g o r i t h m s , S e p t e m b e r , 1 9 9 4 , p p . 1 4 1 - 1 5 5 .

    1 4

  • 8/14/2019 Moir Anderson Sc495

    15/31

    A C o r r e c t n e s s P r o o f f o r A l g o r i t h m i n F i g u r e 4

    T h e f o l l o w i n g s i m p l e p r o p e r t i e s f o l l o w d i r e c t l y f r o m t h e p r o g r a m t e x t i n F i g u r e 4 , a n d a r e s t a t e d w i t h o u t

    p r o o f . N o t e t h a t ( I 2 ) c a n b e u s e d t o p r o v e ( I 3 ) a n d ( I 5 ) a n d t h a t ( I 3 ) c a n b e u s e d t o p r o v e ( I 4 ) .

    i n v a r i a n t p i 0 p j 0 ( I 1 )

    i n v a r i a n t p @ f 0 3 g ) : p s t o p ( I 2 )

    i n v a r i a n t p @ f 0 3 g _ ( p @ f 4 5 g p s t o p ) ) p i + p : j < k ; 1 ( I 3 )

    i n v a r i a n t p @ f 4 5 g ^ : p s t o p ) p i + p j = k ; 1 ( I 4 )

    i n v a r i a n t 0 p i + p j k ; 1 ( I 5 )

    i n v a r i a n t p @ 5 ) p : n a m e = ( p i ) k ; ( p i ) ( p i ; 1 ) = 2 + p j ( I 6 )

    F o r e a c h o f t h e r e m a i n i n g i n v a r i a n t s , a c o r r e c t n e s s p r o o f i s g i v e n .

    2

    i n v a r i a n t r 0 c 0 r + c < k ; 1 Y r c )

    ( 9 p ( p @ f 3 5 g p i = r p j = c ) _ ( p : i > r p j = c ) ) ( I 7 )

    P r o o f : A s s u m e r 0 c 0 r + c < k ; 1 . I n i t i a l l y Y r c ] i s f a l s e , s o ( I 7 ) h o l d s . T o p r o v e t h a t ( I 7 ) i s n o t

    f a l s i e d , i t s u c e s t o c o n s i d e r t h o s e s t a t e m e n t s t h a t m a y e s t a b l i s h

    3

    Y r c ] , o r t h a t m a y f a l s i f y p @ f 3 5 g o r

    m o d i f y p i o r p j f o r s o m e p . T h e s t a t e m e n t s t o c h e c k a r e q 2 p 1 , a n d p 3 , w h e r e q i s a n y p r o c e s s . O b s e r v e

    t h a t q 2 m a y e s t a b l i s h Y r c ] o n l y i f e x e c u t e d w h e n q i = r a n d q j = c , i n w h i c h c a s e i t a l s o e s t a b l i s h e s

    q @ 3 q i = r q j = c . T o s h o w t h a t s t a t e m e n t p 1 d o e s n o t f a l s i f y ( I 7 ) , w e c o n s i d e r t h e f o l l o w i n g t h r e e

    c a s e s .

    4

    C a s e 1 p @ 1 p : i > r p j = c Y p : i p : j ( I 7 )

    r c

    p : i p : j

    ) p @ 1 p : i > r p j = c p i 0 p j 0 p i + p : j < k ; 1 Y p : i p : j ( I 7 )

    r c

    p : i p : j

    , b y ( I 1 ) a n d ( I 3 ) .

    ) p @ 1 p : i > r p j = c ( 9 q ( q @ f 3 5 g q i = p i q j = p j ) _

    ( q : i > p : i q j = p j ) ) , b y d e n i t i o n o f ( I 7 ) , r e n a m i n g p t o q

    ) ( 9 q q 6= p q : i > r q j = c ) , b e c a u s e p @ 1 ( q @ f 3 5 g _ q : i > p : i ) i m p l i e s p 6= q

    f p @ 1 p : i > r p j = c Y p : i p : j ( I 7 )

    r c

    p : i p : j

    g p 1 f ( 9 q q 6= p q : i > r q j = c ) g

    , b y p r e c e d i n g d e r i v a t i o n , p r e c o n d i t i o n i m p l i e s p o s t c o n d i t i o n , w h i c h i s n o t f a l s i e d b y p 1

    C a s e 2 f p @ 1 p : i > r p j = c ^ : Y p : i p : j g p 1 f p : i > r p j = c g

    p 1 d o e s n o t m o d i f y p j i n t h i s c a s e .

    C a s e 3 f p @ 1 ^ : ( p : i > r p j = c ) ( I 7 ) g p 1

    f : Y r c _ ( 9 q q 6= p ( q @ f 3 5 g q i = r q j = c ) _ ( q : i > r q j = c ) ) g

    , b y d e n i t i o n o f ( I 7 ) , p r e c o n d i t i o n i m p l i e s p o s t c o n d i t i o n , w h i c h i s u n c h a n g e d b y p 1

    2

    W e p r o v e t h a t a n a s s e r t i o n I i s a n i n v a r i a n t b y s h o w i n g t h a t i t h o l d s i n d u c t i v e l y o r t h a t i t f o l l o w s f r o m e s t a b l i s h e d i n v a r i a n t s .

    F o r a n i n d u c t i v e p r o o f , w e s h o w t h a t I h o l d s i n i t i a l l y a n d t h a t I i s n o t f a l s i e d b y a n y s t a t e m e n t e x e c u t i o n , i . e . , i f I ( a n d

    p e r h a p s o t h e r e s t a b l i s h e d i n v a r i a n t s ) h o l d s b e f o r e a g i v e n s t a t e m e n t i s e x e c u t e d t h e n I h o l d s a f t e r w a r d s .

    3

    W e s a y t h a t a n e x e c u t i o n o f s t a t e m e n t p i e s t a b l i s h e s a p r e d i c a t e P : P h o l d s b e f o r e t h a t s t a t e m e n t e x e c u t i o n a n d P

    h o l d s a f t e r w a r d s .

    4

    I n t h e r s t c a s e , w e u s e ( I 7 )

    r c

    p : i p : j

    i n t h e p r e c o n d i t i o n . R e c a l l t h a t f r e e v a r i a b l e s a r e a s s u m e d t o b e u n i v e r s a l l y q u a n t i e d ,

    s o t h i s a m o u n t s t o u n i v e r s a l i n s t a n t i a t i o n o f ( I 7 ) ( w h i c h i s a s s u m e d t o h o l d b e f o r e t h e e x e c u t i o n o f s t a t e m e n t p 1 )

    1 5

  • 8/14/2019 Moir Anderson Sc495

    16/31

    T o s h o w t h a t s t a t e m e n t p 3 d o e s n o t f a l s i f y ( I 7 ) , w e c o n s i d e r t h e f o l l o w i n g t h r e e c a s e s .

    f p @ 3 p i r p j = c X p : i p : j = p g p 3 f p @ 4 p i r p j = c g

    p i i s u n c h a n g e d a n d p s t o p i s e s t a b l i s h e d i n t h i s c a s e .

    f p @ 3 p i r p j = c X p : i p : j 6= p g p 3 f p : i > r p j = c g p i i s i n c r e m e n t e d i n t h i s c a s e .

    f p @ 3 ^ : ( p i r p j = c ) ( I 7 ) g p 3

    f : Y r c _ ( 9 q q 6= p ( q @ f 3 5 g q i = r q j = c ) _ ( q : i > r q j = c ) ) g

    , b y d e n i t i o n o f ( I 7 ) , p r e c o n d i t i o n i m p l i e s p o s t c o n d i t i o n , w h i c h i s u n c h a n g e d b y p 3 2

    T h e f o l l o w i n g i n v a r i a n t s h o w s t h a t i f X r c ] h a s b e e n m o d i e d s i n c e p r o c e s s q a s s i g n e d X r c ] , t h e n t h e r e

    i s s o m e p r o c e s s p i n r o w r a t o r t o t h e r i g h t o f c o l u m n c . T h i s p r o p e r t y i s u s e d t o s h o w t h a t n o t a l l p r o c e s s e s

    t h a t a c c e s s b u i l d i n g b l o c k ( r c ) p r o c e e d t o r o w r + 1

    i n v a r i a n t r 0 c 0 r + c < k ; 1 q @ f 1 3 g q i = r q j = c X r c 6= q )

    ( 9 p p 6= q p i = r ( ( p j = c ( ( p @ f 1 3 g X r c = p ) _ p @ f 4 5 g ) ) _ p : j > c ) ) ( I 8 )

    P r o o f : A s s u m e r 0 c 0 r + c < k ; 1 . I n i t i a l l y q @ 0 h o l d s , s o ( I 8 ) h o l d s . T o p r o v e t h a t ( I 8 ) i s n o t

    f a l s i e d , i t s u c e s t o c o n s i d e r t h o s e s t a t e m e n t s t h a t m a y e s t a b l i s h q @ f 1 3 g f a l s i f y p @ f 1 3 g o r p @ f 4 5 g

    o r m o d i f y q i q j X p i o r p j , w h e r e p 6= q . T h e s t a t e m e n t s t o c h e c k a r e q 0 q 1 q 3 p 0 p 1 , a n d p 3

    O b s e r v e t h a t q i = r q j = c X r c 6= q d o e s n o t h o l d a f t e r t h e e x e c u t i o n o f q 0 , a n d t h a t q 1 a n d

    q 3 b o t h e s t a b l i s h q @ f 0 4 g i f t h e y m o d i f y q i o r q j . F u r t h e r m o r e , p 0 e s t a b l i s h e s X r c 6= q o n l y i f p i = r

    a n d p j = c , i n w h i c h c a s e p @ 1 p i = r p j = c X r c = p h o l d s a f t e r w a r d s . A l s o , s t a t e m e n t p 1

    c a n o n l y i n c r e m e n t p j . T h e r e f o r e , i f p 1 f a l s i e s p j = c , t h e n i t e s t a b l i s h e s p : j > c , a n d i t d o e s n o t f a l s i f y

    p i = r

    T h i s l e a v e s o n l y s t a t e m e n t p 3 . S t a t e m e n t p 3 c o u l d f a l s i f y ( I 8 ) o n l y b y f a l s i f y i n g p i = r p j =

    c X r c = p o r b y f a l s i f y i n g p i = r p : j > c . I n t h e r s t c a s e , w e h a v e f p @ 3 p i = r p j =

    c X r c = p g p 3 f p @ 4 p i = r p j = c g s o p 3 d o e s n o t f a l s i f y ( I 8 ) . F o r t h e s e c o n d c a s e , o b s e r v e

    t h a t p 3 c a n f a l s i f y p i = r p : j > c o n l y i f e x e c u t e d w h e n p @ 3 p i = r p : j > c X p : i p : j 6= p

    h o l d s . T o s h o w t h a t s t a t e m e n t p 3 d o e s n o t f a l s i f y ( I 3 ) i n t h i s c a s e , w e c o n s i d e r t h e f o l l o w i n g t w o c a s e s .

    C a s e 1 f p @ 3 p i = r p : j > c X p : i p : j 6= p ( q i 6= r _ q j 6= c ) g p 3 f q i 6= r _ q j 6= c g

    p 3 d o e s n o t m o d i f y q i o r q j ( r e c a l l t h a t p 6= q )

    C a s e 2 p @ 3 p i = r p : j > c X p : i p : j 6= p q i = r q j = c ( I 8 )

    q r c

    p p : i p : j

    ) p @ 3 p i = r p : j > c q j = c p i 0 p j 0 p i + p : j < k ; 1

    X p : i p : j 6= p ( I 8 )

    q r c

    p p : i p : j

    , b y ( I 1 ) a n d ( I 3 ) .

    ) p @ 3 p i = r p : j > c q j = c ( 9 s s 6= p s i = p i

    ( ( s j = p j ( ( s @ f 1 3 g X p : i p : j = s ) _ s @ f 4 5 g ) ) _ s : j > p : j ) ) )

    , b y d e n i t i o n o f ( I 8 ) , r e n a m i n g p t o s

    ) p : j > c q j = c ( 9 s s 6= p s i = r s : j > c ) , p r e d i c a t e c a l c u l u s .

    ) ( 9 s s 6= p s 6= q s i = r s : j > c ) q j = c s : j > c i m p l i e s s 6= q

    f p @ 3 p i = r p : j > c X p : i p : j 6= p q i = r q j = c ( I 8 )

    q r c

    p p : i p : j

    g p 3

    f ( 9 s s 6= p s 6= q s i = r s : j > c ) g

    , b y p r e c e d i n g d e r i v a t i o n , p r e c o n d i t i o n i m p l i e s p o s t c o n d i t i o n , w h i c h i s n o t f a l s i e d b y p 3 2

    1 6

  • 8/14/2019 Moir Anderson Sc495

    17/31

    T h e f o l l o w i n g i n v a r i a n t s h o w s t h a t a t m o s t k ; ( r + c ) p r o c e s s e s a c c e s s b u i l d i n g b l o c k s i n t h e \ s u b - g r i d "

    w h o s e t o p l e f t c o r n e r i s a t p o s i t i o n ( r c ) . I n p a r t i c u l a r , i t s h o w s t h a t a t m o s t o n e p r o c e s s a c c e s s e s a n y

    b u i l d i n g b l o c k t h a t i s k ; 1 \ s t e p s " a w a y f r o m t h e t o p l e f t c o r n e r o f t h e g r i d .

    i n v a r i a n t r 0 c 0 r + c k ; 1 ) ( f p p i r p j c g k ; ( r + c ) ) ( I 9 )

    P r o o f : A s s u m e r 0 c 0 r + c k ; 1 . I n i t i a l l y p i = 0 p j = 0 h o l d s f o r a l l p , s o ( I 9 ) h o l d s . T o

    p r o v e t h a t ( I 9 ) i s n o t f a l s i e d , i t s u c e s t o c o n s i d e r t h o s e s t a t e m e n t s t h a t m a y e s t a b l i s h q i r q j c

    f o r s o m e q . T h e r e a r e t w o s t a t e m e n t s t o c h e c k , n a m e l y q 1 a n d q 3

    O b s e r v e t h a t s t a t e m e n t q 1 c a n e s t a b l i s h q i r q j c o n l y i f e x e c u t e d w h e n q i r q j =

    c ; 1 Y q : i q : j ] h o l d s . T o s e e t h a t ( I 9 ) i s n o t f a l s i e d i n t h i s c a s e , c o n s i d e r t h e f o l l o w i n g d e r i v a t i o n .

    q @ 1 q i r q j = c ; 1 Y q : i q : j ( I 7 )

    r c

    q : i q : j

    ( I 9 )

    c

    c 1

    ) q @ 1 q i r q j = c ; 1 q i 0 q j 0 q i + q : j < k ; 1 Y q : i q : j ( I 7 )

    r c

    q : i q : j

    c ; 1 0 ( I 9 )

    c

    c 1

    , b y ( I 1 ) a n d ( I 3 ) n o t e t h a t q j = c ; 1 ( I 1 ) i m p l i e s c ; 1 0

    ) q i r q j = c ; 1 ( 9 s s 6= q s i q i s j = q j ) c ; 1 0 ( I 9 )

    c

    c 1

    , d e n i t i o n o f ( I 7 ) n o t e t h a t q @ 1 ( s @ f 3 5 g _ s : i > q : i ) i m p l i e s s 6= q

    ) ( f s s i r s j = c ; 1 g 2 c ; 1 0 ) ( f p p i r p j c ; 1 g k ; ( r + c ) + 1 )

    , p r e d i c a t e c a l c u l u s a n d d e n i t i o n o f ( I 9 ) r e c a l l t h a t r 0 a n d r + c k ; 1

    ) f p p i r p j c g k ; ( r + c ) ; 1 , p r e d i c a t e c a l c u l u s .

    f q @ 1 q i r q j = c ; 1 Y q : i q : j ( I 7 )

    r c

    q : i c 1

    ( I 9 )

    c

    c 1

    g q 1

    f f q q i r q j c g k ; ( r + c ) g

    , b y p r e c e d i n g d e r i v a t i o n q 1 i n c r e a s e s f q q i r q j c g b y a t m o s t o n e .

    S t a t e m e n t q 3 c a n e s t a b l i s h q i r q j c o n l y i f e x e c u t e d w h e n q i = r ; 1 q j c X q : i q : j 6= q

    h o l d s . T h e r e a s o n i n g f o r t h i s c a s e i s s i m i l a r t o t h a t g i v e n a b o v e f o r s t a t e m e n t q 1 , e x c e p t t h a t ( I 8 ) i s u s e d

    i n s t e a d o f ( I 7 ) . 2

    i n v a r i a n t p @ 3 _ ( p @ f 4 5 g p s t o p ) ) Y p : i p : j ] ( I 1 0 )

    P r o o f : I n i t i a l l y p @ 0 h o l d s , s o ( I 1 0 ) h o l d s . ( I 1 0 ) i s p o t e n t i a l l y f a l s i e d b y a n y s t a t e m e n t t h a t e s t a b l i s h e s

    p @ 3 o r p @ f 4 5 g p s t o p o r t h a t m o d i e s p i o r p j . ( N o t e t h a t n o s t a t e m e n t f a l s i e s a n y e l e m e n t o f

    Y . ) T h e s t a t e m e n t s t o c h e c k a r e p 1 p 2 , a n d p 3 . B y ( I 2 ) , p 1 e s t a b l i s h e s p @ f 0 2 4 g ^ : p : s t o p , t h e r e b y

    f a l s i f y i n g t h e a n t e c e d e n t . A l s o , s t a t e m e n t p 2 e s t a b l i s h e s Y p : i p : j ] . T o s h o w t h a t p 3 d o e s n o t f a l s i f y ( I 1 0 ) ,

    w e c o n s i d e r t h e f o l l o w i n g t w o c a s e s .

    f p @ 3 X p : i : p : j = p ( I 1 0 ) g p 3 f Y p : i p : j g

    , b y d e n i t i o n o f ( I 1 0 ) , p r e c o n d i t i o n i m p l i e s p o s t c o n d i t i o n p 3 d o e s n o t m o d i f y Y p i o r p j i n t h i s c a s e .

    f p @ 3 X p : i p : j 6= p g p 3 f p @ f 0 4 g ^ : p : s t o p g , b y ( I 2 ) , p r e c o n d i t i o n i m p l i e s : p : s t o p 2

    T h e f o l l o w i n g i n v a r i a n t s h o w s t h a t i f s o m e p r o c e s s p s t o p s a t b u i l d i n g b l o c k ( r c ) , t h e n n o o t h e r p r o c e s s

    s t o p s a t t h a t b u i l d i n g b l o c k . T h i s p r o p e r t y i s u s e d t o s h o w t h a t p r o c e s s e s t h a t s t o p i n t h e g r i d r e c e i v e

    d i s t i n c t n a m e s .

    i n v a r i a n t p 6= q p @ f 4 5 g p s t o p ) ( q i 6= p i _ q j 6= p j _ q @ 0 _

    ( q @ 1 Y q : i q : j ) _ ( q @ f 1 3 g X q : i q : j 6= q ) _ ( q @ f 4 5 g ^ : q s t o p ) ) ( I 1 1 )

    1 7

  • 8/14/2019 Moir Anderson Sc495

    18/31

    P r o o f : A s s u m e t h a t p 6= q . I n i t i a l l y p @ 0 h o l d s , s o ( I 1 1 ) h o l d s . T o p r o v e t h a t ( I 1 1 ) i s n o t f a l s i e d , i t s u c e s

    t o c o n s i d e r t h o s e s t a t e m e n t s t h a t m a y e s t a b l i s h p @ f 4 5 g p s t o p o r q s t o p f a l s i f y q @ 0 q @ 1 q @ f 1 3 g o r

    q f 4 5 g o r m o d i f y p i p j q i q j X o r Y . T h e s t a t e m e n t s t o c h e c k a r e p 0 p 1 p 2 p 3 q 0 q 1 q 2 , a n d

    q 3 . O b s e r v e t h a t p @ f 4 5 g i s f a l s e a f t e r t h e e x e c u t i o n o f p 0 o r p 2 . A l s o , b y ( I 2 ) , p : s t o p i s f a l s e a f t e r t h e

    e x e c u t i o n o f p 1 . F o r p 3 , w e h a v e t h e f o l l o w i n g f o u r c a s e s .

    f p @ 3 X p : i p : j 6= p g p 3 f p @ 0 _ ( p @ 4 ^ : p : s t o p ) g , b y ( I 2 ) , p r e c o n d i t i o n i m p l i e s : p : s t o p

    f p @ 3 X p : i p : j = p ( q i 6= p i _ q j 6= p j _ q @ 0 ) g p 3 f q i 6= p i _ q j 6= p j _ q @ 0 g

    , p r e c o n d i t i o n i m p l i e s p o s t c o n d i t i o n ( r e c a l l t h a t p 6= q ) p 3 d o e s n o t m o d i f y p i i n t h i s c a s e .

    f p @ 3 X p : i p : j = p q i = p i q j = p j q @ f 1 3 g g p 3 f q @ f 1 3 g X q : i q : j 6= q g

    p 6= q , s o p r e c o n d i t i o n i m p l i e s p o s t c o n d i t i o n , w h i c h i s n o t f a l s i e d b y p 3

    f p @ 3 X p : i p : j = p q i = p i q j = p j q @ f 4 5 g ( I 1 1 )

    p q

    q p

    g p 3 f q @ f 4 5 g ^ : q s t o p g

    , b y t h e d e n i t i o n o f ( I 1 1 ) , p r e c o n d i t i o n i m p l i e s p o s t c o n d i t i o n , w h i c h i s n o t f a l s i e d b y p 3

    T h e a b o v e a s s e r t i o n s i m p l y t h a t p 3 d o e s n o t f a l s i f y ( I 1 1 ) . A s f o r p r o c e s s q , r s t n o t e t h a t q 0 e s t a b l i s h e s

    q @ 1 , w h i c h w i t h ( I 1 0 ) i m p l i e s t h a t : ( p @ f 4 5 g p : s t o p ) _ ( q @ 1 Y p : i p : j ] ) h o l d s . T h e l a t t e r d i s j u n c t

    i m p l i e s t h a t q i 6= p i _ q j 6= p j _ ( q @ 1 Y q : i q : j ] ) h o l d s . S t a t e m e n t q 1 c a n f a l s i f y ( I 1 1 ) o n l y i f

    e x e c u t e d w h e n q @ 1 Y q : i q : j o r q @ f 1 3 g X q : i q : j 6= q h o l d s . H o w e v e r , o b s e r v e t h e f o l l o w i n g .

    f q @ 1 Y q : i q : j g q 1 f q @ 0 _ ( q @ 4 ^ : q : s t o p ) g , b y ( I 2 ) , p r e c o n d i t i o n i m p l i e s : q s t o p

    f q @ 1 ^ : Y q : i q : j X q : i q : j 6= q g q 1 f q @ 2 X q : i q : j 6= q g q 1 d o e s n o t m o d i f y q j i n t h i s c a s e .

    A l t h o u g h q 2 m o d i e s Y , i t c a n n o t f a l s i f y a n y d i s j u n c t o f t h e c o n s e q u e n t o f ( I 1 1 ) .

    S t a t e m e n t q 3 c o u l d f a l s i f y ( I 1 1 ) o n l y b y f a l s i f y i n g q @ 3 X q : i q : j 6= q . H o w e v e r , b e c a u s e q @ 3 ( I 2 )

    i m p l i e s : q s t o p , w e h a v e f q @ 3 X q : i q : j 6= q ( I 2 ) g q 3 f q @ 0 _ ( q @ 4 ^ : q : s t o p ) g 2

    T h e f o l l o w i n g i n v a r i a n t s h o w s t h a t d i s t i n c t p r o c e s s e s d o n o t a c q u i r e a n a m e f r o m t h e s a m e g r i d p o s i t i o n .

    i n v a r i a n t p 6= q p @ f 4 5 g q @ f 4 5 g ) p i 6= q i _ q j 6= q j ( I 1 2 )

    P r o o f : I f p 6= q p @ f 4 5 g q @ f 4 5 g p s t o p h o l d s , t h e n b y ( I 4 ) , ( I 3 ) , a n d ( I 1 1 ) , t h e c o n s e q u e n t h o l d s . I f

    p 6= q p @ f 4 5 g q @ f 4 5 g ^ : p s t o p h o l d s , t h e n b y ( I 1 ) , ( I 4 ) , a n d ( I 9 ) , f q q i p i q j p j g 1

    h o l d s , w h i c h i m p l i e s t h a t t h e c o n s e q u e n t h o l d s . 2

    C l a i m 1 : L e t c d c , a n d d b e n o n n e g a t i v e i n t e g e r s s a t i s f y i n g ( c 6= c _ d 6= d ) ( c + d k ; 1 ) ( c + d

    k ; 1 ) . T h e n , c k ; c ( c ; 1 ) = 2 + d 6= c k ; c ( c ; 1 ) = 2 + d

    P r o o f : T h e c l a i m i s s t r a i g h t f o r w a r d i f c = c , s o a s s u m e t h a t c 6= c . W i t h o u t l o s s o f g e n e r a l i t y a s s u m e t h a t

    c < c . T h e n ,

    c k ; c ( c ; 1 ) = 2 + d c k ; c ( c ; 1 ) = 2 + k ; 1 ; c d k ; 1 ; c

    = c k ; c

    2

    = 2 ; c = 2 + k ; 1

  • 8/14/2019 Moir Anderson Sc495

    19/31

    p @ 5 q @ 5 p 6= q

    ) p @ 5 q @ 5 ( p i 6= q i _ p j 6= q j ) p i + p j k ; 1 q i + q j k ; 1 , b y ( I 5 ) a n d ( I 1 2 ) .

    ) p @ 5 q @ 5 ( p i ) k ; ( p i ) ( p i ; 1 ) = 2 + p j 6= ( q i ) k ; ( q i ) ( q i ; 1 ) = 2 + q j

    , b y C l a i m 1 w i t h c = p i d = p j c = q i , a n d d = q j

    ) p n a m e 6= q n a m e , b y ( I 6 ) . 2

    T h i s c o m p l e t e s t h e p r o o f t h a t d i s t i n c t p r o c e s s e s t h a t e x e c u t e t h e c o d e i n F i g u r e 4 a c q u i r e d i s t i n c t n a m e s .

    T h e f o l l o w i n g c l a i m i s u s e d t o p r o v e t h a t e a c h p r o c e s s a c q u i r e s a n a m e r a n g i n g o v e r f 0 k ( k + 1 ) = 2 ; 1 g

    C l a i m 2 : L e t c a n d d b e n o n n e g a t i v e i n t e g e r s s a t i s f y i n g c + d k ; 1 . T h e n 0 c k ; c ( c ; 1 ) = 2 + d < k ( k + 1 ) = 2

    P r o o f : I t f o l l o w s f r o m t h e s t a t e m e n t o f t h e c l a i m t h a t c k ; 1 . T h u s , k ; ( c ; 1 ) = 2 > 0 . A l s o , c 0 a n d

    d 0 . T h u s , c k ; c ( c ; 1 ) = 2 + d 0 . T o s e e t h a t c k ; c ( c ; 1 ) = 2 + d < k ( k + 1 ) = 2 , c o n s i d e r t h e f o l l o w i n g

    d e r i v a t i o n .

    c k ; c ( c ; 1 ) = 2 + d c k ; c ( c ; 1 ) = 2 + d ( d + 1 ) = 2 d 0

    c k ; c ( c ; 1 ) = 2 + ( k ; 1 ; c ) ( k ; c ) = 2 d k ; 1 ; c

    = c + k ( k ; 1 ) = 2

    k ; 1 + k ( k ; 1 ) = 2 c k ; 1

    < k ( k + 1 ) = 2 2

    i n v a r i a n t p @ 5 ) 0 p n a m e < k ( k + 1 ) = 2 ( I 1 4 )

    P r o o f : ( I 1 4 ) f o l l o w s f r o m ( I 1 ) , ( I 5 ) , ( I 6 ) , a n d C l a i m 2 . 2

    ( I 1 3 ) a n d ( I 1 4 ) p r o v e t h a t t h e a l g o r i t h m s h o w n i n F i g u r e 4 c o r r e c t l y i m p l e m e n t s ( k ( k + 1 ) = 2 ) - r e n a m i n g .

    W a i t - f r e e d o m i s t r i v i a l b e c a u s e i n e a c h p a s s t h r o u g h t h e l o o p , e i t h e r p s t o p i s e s t a b l i s h e d , o r p i o r p j i s

    i n c r e m e n t e d . I t i s e a s y t o s e e t h a t a p r o c e s s e x e c u t e s t h e l o o p a t m o s t k ; 1 t i m e s b e f o r e t e r m i n a t i n g . E a c h

    i t e r a t i o n p e r f o r m s a t m o s t f o u r s h a r e d v a r i a b l e a c c e s s e s . T h u s , w e h a v e t h e f o l l o w i n g r e s u l t .

    T h e o r e m 1 U s i n g r e a d a n d w r i t e , w a i t - f r e e , o n e - t i m e ( k ( k + 1 ) = 2 ) - r e n a m i n g c a n b e i m p l e m e n t e d s o t h a t

    t h e w o r s t - c a s e t i m e c o m p l e x i t y o f a c q u i r i n g a n a m e o n c e i s 4 ( k ; 1 ) 2

    B C o r r e c t n e s s P r o o f f o r A l g o r i t h m i n F i g u r e 5

    I n a c c o r d a n c e w i t h t h e p r o b l e m s p e c i c a t i o n , w e a s s u m e t h e f o l l o w i n g i n v a r i a n t .

    i n v a r i a n t f p p @ f 1 8 g k ( I 1 5 )

    T h e f o l l o w i n g s i m p l e p r o p e r t i e s f o l l o w d i r e c t l y f r o m t h e p r o g r a m t e x t i n F i g u r e 5 , a n d a r e s t a t e d w i t h o u t

    p r o o f . N o t e t h a t ( I 1 7 ) c a n b e u s e d t o p r o v e ( I 1 8 ) a n d ( I 1 9 ) .

    i n v a r i a n t p @ 5 _ ( p @ f 6 8 g p m o v e = s t o p ) ) Y p : i p : j p ] ( I 1 6 )

    i n v a r i a n t p @ f 2 6 g _ ( p @ f 6 8 g p m o v e = s t o p ) ) p i + p : j < k ; 1 ( I 1 7 )

    i n v a r i a n t p @ f 7 8 g p m o v e 6= s t o p ) p i + p j = k ; 1 ( I 1 8 )

    i n v a r i a n t 0 p i + p j k ; 1 ( I 1 9 )

    1 9

  • 8/14/2019 Moir Anderson Sc495

    20/31

    i n v a r i a n t p i 0 p j 0 ( I 2 0 )

    i n v a r i a n t p @ 3 ) 0 p : h < N ( I 2 1 )

    i n v a r i a n t p @ 8 ) p n a m e = ( p i ) k ; ( p i ) ( p i ; 1 ) = 2 + p j ( I 2 2 )

    F o r e a c h o f t h e r e m a i n i n g i n v a r i a n t s , a c o r r e c t n e s s p r o o f i s g i v e n . T h e f o l l o w i n g i n v a r i a n t s h o w s t h a t i f

    Y r c p ] h o l d s , t h e n p r o c e s s p h a s e i t h e r s t o p p e d a t b u i l d i n g b l o c k ( r c ) o r h a s d e c i d e d t o m o v e d o w n f r o m

    b u i l d i n g b l o c k ( r c ) , b u t h a s n o t y e t r e s e t t h e b u i l d i n g b l o c k .

    i n v a r i a n t r 0 c 0 r + c < k ; 1 Y r c p )

    p @ f 5 8 g p i = r p j = c p m o v e 6= r i g h t ( I 2 3 )

    P r o o f : A s s u m e r 0 c 0 r + c < k ; 1 . I n i t i a l l y Y r c p ] i s f a l s e , s o ( I 2 3 ) h o l d s . T o p r o v e t h a t

    ( I 2 3 ) i s n o t f a l s i e d , i t s u c e s t o c o n s i d e r s t a t e m e n t s t h a t p o t e n t i a l l y e s t a b l i s h Y r c p ] , f a l s i f y p @ f 5 8 g

    m o d i f y p i o r p j , o r e s t a b l i s h p m o v e = r i g h t . T h e s t a t e m e n t s t o c h e c k a r e p 1 p 3 p 4 p 6 a n d p 8

    O b s e r v e t h a t p @ f 1 3 g ( I 2 3 ) ) : Y r c p ] a n d t h a t s t a t e m e n t s p 1 a n d p 3 d o n o t m o d i f y Y . H e n c e ,

    t h e s e s t a t e m e n t s d o n o t f a l s i f y ( I 2 3 ) . N o t e a l s o t h a t : Y r c p _ p i 6= r _ p j 6= c h o l d s a f t e r s t a t e m e n t

    p 8 i s e x e c u t e d ( r e c a l l t h a t r + c < k ; 1 ) . T h u s , p 8 c a n n o t f a l s i f y ( I 2 3 ) . F o r s t a t e m e n t p 4 , w e h a v e t h e

    f o l l o w i n g t w o c a s e s .

    f p @ 4 p i = r p j = c p m o v e 6= r i g h t g p 4 f p @ 5 p i = r p j = c p m o v e 6= r i g h t g

    , b y p r o g r a m t e x t .

    f p @ 4 ( p i 6= r _ p j 6= c _ p m o v e = r i g h t ) ( I 2 3 ) g p 4 f : Y r c p g

    p @ 4 ( I 2 3 ) i m p l i e s : Y r c p p 4 d o e s n o t m o d i f y Y r c p ] w h e n

    p i 6= r _ p j 6= c _ p m o v e = r i g h t h o l d s .

    T o s h o w t h a t s t a t e m e n t p 6 d o e s n o t f a l s i f y ( I 2 3 ) , w e c o n s i d e r t h e f o l l o w i n g t h r e e c a s e s .

    f p @ 6 p i = r p j = c p m o v e = s t o p g p 6 f p @ 7 p i = r p j = c p m o v e 6= r i g h t g

    , b y p r o g r a m t e x t .

    f p @ 6 p i = r p j = c p m o v e 6= s t o p g p 6 f : Y r c p g , b y p r o g r a m t e x t .

    f p @ 6 ^ : ( p i = r p j = c ) ( I 2 3 ) g p 6 f : Y r c p g

    : ( p i = r p j = c ) ( I 2 3 ) i m p l i e s : Y r c p p 6 d o e s n o t e s t a b l i s h Y r c p 2

    F o r n o t a t i o n a l c o n v e n i e n c e , w e d e n e t h e f o l l o w i n g p r e d i c a t e .

    D e n i t i o n E N ( p r c ) ( p i = r ; 1 p j c p @ f 3 5 g X r ; 1 p : j 6= p ) _

    ( p i = r ; 1 p j c p @ 6 p m o v e = d o w n ) _

    ( p i r p j = c ; 1 p @ f 4 6 g p m o v e = r i g h t ) _

    ( p i r p j c p @ f 2 8 g ) 2

    I n f o r m a l l y , E N ( p r c ) h o l d s f o r a n y p f o r w h i c h p i r p j c w i l l e v e n t u a l l y h o l d , r e g a r d l e s s o f t h e

    b e h a v i o r o f p r o c e s s e s o t h e r t h a n p . N o t e t h a t i f t h e r s t d i s j u n c t h o l d s , t h e n t h e s e c o n d d i s j u n c t h o l d s a f t e r

    p 5 i s e x e c u t e d . I f t h e s e c o n d o r t h i r d d i s j u n c t h o l d s , t h e n p i r p j c h o l d s a f t e r p 6 i s e x e c u t e d .

    W e u s e t h i s p r e d i c a t e i n ( I 2 5 ) t o s h o w t h a t a t m o s t o n e p r o c e s s c o n c u r r e n t l y a c c e s s e s a b u i l d i n g b l o c k t h a t

    i s k ; 1 s t e p s a w a y f r o m t h e t o p l e f t b u i l d i n g b l o c k i n t h e g r i d . T h i s s h o w s w h y a p r o c e s s t h a t t a k e s k ; 1

    s t e p s i n t h e g r i d c a n b e a s s i g n e d a n a m e i m m e d i a t e l y .

    2 0

  • 8/14/2019 Moir Anderson Sc495

    21/31

    i n v a r i a n t E N ( p r c ) ) E N ( p r c ; 1 ) E N ( p r ; 1 c ) ( I 2 4 )

    P r o o f : ( I 2 4 ) f o l l o w s d i r e c t l y f r o m t h e d e n i t i o n o f E N ( p r c ) . I f e i t h e r o f t h e r s t t w o d i s j u n c t s o f E N ( p r c )

    h o l d s , t h e n t h a t d i s j u n c t o f E N ( p r c ; 1 ) a l s o h o l d s b e c a u s e c > c ; 1 . I f e i t h e r o f t h e l a s t t w o d i s j u n c t s

    o f E N ( p r c ) h o l d s , t h e n t h e l a s t d i s j u n c t o f E N ( p r c ; 1 ) h o l d s . I f t h e r s t , s e c o n d , o r l a s t d i s j u n c t o f

    E N ( p r c ) h o l d s , t h e n t h e l a s t d i s j u n c t o f E N ( p r ; 1 c ) h o l d s . F i n a l l y , i f t h e t h i r d d i s j u n c t o f E N ( p r c )

    h o l d s , t h e n t h e t h i r d d i s j u n c t o f E N ( p r ; 1 c ) h o l d s b e c a u s e r > r ; 1 2

    T h e f o l l o w i n g i n v a r i a n t i s a n a l o g o u s t o ( I 9 ) .

    i n v a r i a n t r 0 c 0 r + c k ; 1 ) ( f p E N ( p r c ) g k ; ( r + c ) ) ( I 2 5 )

    P r o o f : A s s u m e r 0 c 0 r + c k ; 1 . I n i