# dynamic arrays of ops

resource r ()
    optype t (int)
    const int d1 = 3
    const int d2 = 2

    cap sem s[d1,d2] = new ([d1,d2] sem)
    cap (int) o[d1] = new ([d1] op (int))
    cap t p[d2] = new ([d2] t)

    for [ i = 1 to d1 ] {
	for [ j = 1 to d2 ] {
	    V (s[i][j])
	    send o[i] (100 + 10 * i + j)
	    send p[j] (200 + 10 * i + j)
	}
    }

    for [ i = 1 to d1 ] { writes (" ", ?o[i]) };  write ("\t(o)")
    for [ j = 1 to d2 ] { writes (" ", ?p[j]) };  write ("\t(p)")

    for [ i = 1 to d1 ] {
	for [ j = 1 to d2 ] {
	    writes (" ", ?s[i,j]);
	    P (s[i,j])
	    writes ("/", ?s[i,j]);
	}
    }
    write ("\t (s)")

    for [ i = 1 to d1 ] {
	for [ j = 1 to d2 ] {
	    int  n 
	    receive o[i] (n);  writes (" ", n)
	    in p[j] (x) -> writes (" ", x) ni
	}
    }
    write ("\t(o&p)")

    destroy s
    destroy o
    destroy p

    write ("done")

end
