mutex =1;
for ( i = 0; i≦n2 – 1 ; i ++) {
empty[i]=m; full [i]=0; }
main ( ) {
cobegin
A1 ( ) ;
A2 ( ) ;
An1 ( ) ; B1 ( ) ; B2 ( ) ;
Bn2 ( ); coend }
send ( ) /*发送消息*/ {
int i;
for ( i = 0; i≦n2 – 1 ; i ++)
p ( empty[i] ) ; P ( mutex ) ;
将消息放入缓冲区;
v ( mutex );
for ( i = 0; i≦n2 – 1 ; i ++)
v ( full [i] ) ;
}
receive ( ) /*进程B1接收消息*/ {
p ( full [i] ) ; P ( mutex ) ;
将消息从缓冲区中取出;
v ( mutex );
… … v ( empty[i] ) ;
}
Ai ( ) /*因发送进程A1、A2,…An1的程序类似,这里只给出进程Ai的描述*/ {
while ( 1 ) {
send ( ); }
Bi ( ) /*因接受进程B1、B2,…Bn1的程序类似,这里只给出进程Bi的描述*/ {
while ( 1 ) {
receive ( i ); }
… … … …