-- Soluzione 1 ----------------------------------------------- int[] array = { T, R, T, T } int last = A; int n=0; Semaphore[] sem = new Semaphore[3] // Init at zero synchroT() { if (last == T) sem[A].V(); sem[T].P(); last = T; n = (n+1) % 4; } synchroR() { if (last == R) sem[A].V(); sem[R].P(); last = R; n = (n+1) % 4; } synchroA() { if (last == A) if (array[n] == T) sem[T].V(); else sem[R].V(); sem[A].P(); last = A; } -- Soluzione 2 ----------------------------------------------- int[] array = { T, A, R, A, T, A, T, A } int last = A; int n=0; Semaphore[] sem = new Semaphore[3] // Init at zero synchro(x) { int prev = (n-1)%8; if (last == array[prev]) sem[array[n]].V(); sem[x].P(); last = x; n = (n+1)%8; }