#include #include #include #include #include #include /* CONSTANTES */ #define NLINS 8 #define NCOLS 8 #define SKEY 123 #define SSIZE NLINS*NCOLS*sizeof(int) /* MACROS */ #define CELL(s,r,c) (*((s)+((r)*NCOLS)+(c))) /* operações sobre semáforos */ #define UP(sid,n) { \ struct sembuf up={n,1,0};\ semop(sid, &up, 1); \ } #define DOWN(sid,n) { \ struct sembuf down={n,-1,0};\ semop(sid, &down, 1); \ } #define INIT(sid,n) UP(sid,n) /* VARIAVEIS GLOBAIS */ int totalLin, totalCol; /* totais na linha e coluna */ int linSems, colSems; /* id vectores de semaforos */ /* PROTOTIPOS DAS FUNCOES */ void gera_nova_entrada(int *); void escreve_e_verifica(int *); int inicia_sems(key_t, int); int main() { int id, lin, col, *folha, i=0, j=0; setbuf(stdout,NULL); /* evita buffering */ totalLin= NLINS-1; totalCol= NCOLS-1; /* seg. mem. partilhada para a matriz */ id= shmget(SKEY, SSIZE,IPC_CREAT|0600); folha= (int *) shmat(id,0,0); for (lin=0; lin < NLINS; lin++) /* celulas a zero */ for (col=0; col