/* This SR file was generated by m2sr */
# 1 "/tmp/m2sr2437.c"
 

# 11

# 15

 
# 21


# 24


 
# 48

# 53

 
# 66

# 76

 
# 93

 
# 109

# 118

# 122

# 127

# 153

# 173

# 198

# 203

 
# 206

# 210

 
# 308

 
# 1 "/tmp/m2sr2437.c"
 
# 5
 /* -- 5 -- */ global barrier
  op setn(n: int), arrive(i: int)
 /* -- 7 -- */ body barrier ; type m_cv_type = rec ( m_wait : cap ( return_to_caller : cap ( ) ; rank : int ) ; m_wait_ranks : cap ( rank : int ) ; m_signal : cap ( ) returns proc_waiting : bool ; m_signal_all : cap ( ) ; m_empty : cap ( ) returns results
 : bool ; m_minrank : cap ( ) returns rank : int ; m_print : cap ( ) ; ) ; op m_condvar ( name : string [ * ] ) returns m_cv : m_cv_type ; sem m_mutex : = 1 ; op m_urgentq ( ) ; var m_n_urgentq : = 0 ; V ( m_mutex ) ; P ( m_mutex ) ; V ( m_urgentq ) ; P (
 m_urgentq )

   /* -- 9 -- */ var b : m_cv_type ; b : = m_condvar ( "b" )
  var cnt := 0, limit : int

   /* -- 12 -- */ proc setn ( n ) op m_return_from_wait ( ) ; send m_return_from_wait ( ) ; receive m_return_from_wait ( ) ; receive m_mutex ( ) ; var m_bozo : bool ; m_bozo : = m_bozo
    limit := n
    write("number of processes is", n)
   /* -- 15 -- */ send m_mutex ( ) ; end

   /* -- 17 -- */ proc arrive ( i ) op m_return_from_wait ( ) ; send m_return_from_wait ( ) ; receive m_return_from_wait ( ) ; receive m_mutex ( ) ; var m_bozo : bool ; m_bozo : = m_bozo
    cnt++
    write("process", i, "has arrived -- total of", cnt)
    if cnt < limit ->  /* -- 20 -- */ send b . m_wait ( m_return_from_wait , 0 ) ; send b . m_wait_ranks ( 0 ) ; send m_mutex ( ) ; receive m_return_from_wait ( ) ; receive m_mutex ( ) ;
    [] else ->
        fa i := 1 to limit-1 ->  /* -- 22 -- */ m_bozo : = b . m_signal ( ) ; af
        cnt := 0
    fi
   /* -- 25 -- */ send m_mutex ( ) ; end

 /* -- 27 -- */ proc m_condvar ( name ) returns m_cv ; op m_wait ( return_to_caller : cap ( ) ; rank : int ) ; op m_wait_ranks ( rank : int ) ; op m_signal ( ) returns proc_waiting : bool ; op m_signal_all ( ) ; op m_empty ( ) returns results : bool ; op 
m_minrank ( ) returns rank : int ; op m_print ( ) ; m_cv . m_wait : = m_wait ; m_cv . m_wait_ranks : = m_wait_ranks ; m_cv . m_signal : = m_signal ; m_cv . m_signal_all : = m_signal_all ; m_cv . m_empty : = m_empty ; m_cv . m_minrank : = m_minrank ; m_cv 
. m_print : = m_print ; reply ; do true -> in m_wait ( return_to_caller , rank ) and ? m_signal != 0 by rank -> in m_wait_ranks ( rank ) by rank -> ni ; in m_signal ( ) returns pw -> pw : = true ; m_n_urgentq ++ ; ni ; send return_to_caller ( ) ; [ ] m_si
gnal ( ) returns pw and ? m_wait = 0 -> pw : = false ; [ ] m_wait ( return_to_caller , rank ) and ? m_signal_all != 0 by rank -> in m_wait_ranks ( rank ) by rank -> ni ; send return_to_caller ( ) ; [ ] m_signal_all ( ) and ? m_wait = 0 -> skip [ ] m_empty
 ( ) returns results -> results : = ( ? m_wait = 0 ) ; [ ] m_minrank ( ) returns ret -> if ? m_wait_ranks != 0 -> in m_wait_ranks ( rank ) by rank -> send m_wait_ranks ( rank ) ; ret : = rank ; ni [ ] else -> write ( "\t**** minrank called on empty Q ****
" ) ; flush ( stdout ) ; ret : = 999999 ; fi [ ] m_print ( ) -> writes ( "\t**** Printing for " , name , " **** " ) ; var x : = ? m_wait ; writes ( x , " waiting process(es)" ) ; if x > 0 -> ; var r , minr : int ; var same : = true ; receive m_wait_ranks 
( r ) ; minr : = r ; send m_wait_ranks ( minr ) ; fa i : = 2 to x -> receive m_wait_ranks ( r ) ; send m_wait_ranks ( r ) ; same : = same and ( r = minr ) ; af ; if same -> writes ( ", all with rank " , r ) ; [ ] else -> op order ( rank : int ) ; write ( 
", with ranks:" ) ; fa i : = 1 to x -> in m_wait_ranks ( rank ) by rank -> writes ( " " , rank ) ; send order ( rank ) ni ; af ; fa i : = 1 to x -> in order ( rank ) -> send m_wait_ranks ( rank ) ni ; af ; fi ; fi ; write ( ) ; flush ( stdout ) ; ni ; od 
; end ; end
#ident "acomp: (CDS) SunOS5.0 IDR3.5 (H6.1) 11/01/90"
