Sistemas Operativos - 2009/20102º Ano, 1º SemestreLEIC - Campus AlamedaLEIC - Campus Tagus Park LERC - Campus Tagus Park |
![]() |
void* thread_producer() { req_t req_d; while(1) { // wait for a free buffer slot sthread_monitor_enter(mon); while (available_reqs == RING_SIZE) sthread_monitor_wait(mon); sthread_monitor_exit(mon); // create and clean request req_d = (req_t) malloc(sizeof(struct _req)); memset(req_d,0,sizeof(struct _req)); if ((req_d->reqsz = srv_recv_request(&(req_d->req),&(req_d->cliaddr),&(req_d->clilen))) == 0) { continue; } sthread_monitor_enter(mon); // send to buffer put_req(req_d); available_reqs++; sthread_monitor_signalall(mon); sthread_monitor_exit(mon); sthread_yield(); } }
Cliente (int idCliente){ EscolherFila ( TempoCompra); SerAtendido(TempoAtendimento); }
void sthread_user_monitor_signalall(sthread_mon_t mon) { struct _sthread *temp; if(mon->mutex->thr != active_thr){ printf("monitor signalall called outside monitor\n"); return; } while(atomic_test_and_set(&(mon->mutex->l))) {} while(!queue_is_empty(mon->queue)){ /* changes blocking queue for thread */ temp = queue_remove(mon->queue); queue_insert(mon->mutex->queue, temp); } atomic_clear(&(mon->mutex->l)); }