Timeouts y Prioridades

nSend(th, *msg);
nReceive(*pth, timeout_ms);msg al thread th.th.pth.timeout_ms.timeout_ms \(< 0\) entonces la suspensión es infinita.Patron Request
void obtenerImpresora(){
pthread_mutex_lock(&m);
Request req = {FALSE,
PTHREAD_COND_INITIALIZER};
put(q, &req);
pthread_cond_signal(&obtener);
while (!req.ready){
pthread_cond_wait(&req.w, &m);
}
pthread_mutex_unlock(&m);
}
void devolverImpresora(){
pthread_mutex_lock(&m);
ocupada = FALSE;
pthread_cond_signal(&devolver);
pthread_mutex_unlock(&m);
}Patron Request
void ImpresoraServer() {
while(TRUE) {
pthread_mutex_lock(&m);
if(emptyQueue(q)) {
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += 60*5;
while(emptyQueue(q) && pthread_cond_timed_wait(&obtener, &m, &ts) != ETIMEDOUT) {
;//wait por 5 mins
}
if(emptyQueue(q)) {
modoBajoConsumo();
while (emptyQueue(q)) {
pthread_cond_wait(&obtener, &m);
}
modoUsoNormal();
}
}
if(!emptyQueue(q)) {
Request *req = get(q);
req -> ready = TRUE;
ocupada = TRUE;
pthread_cond_signal(&req->w);
}
while(ocupada){
pthread_cond_wait(&devolver, &m);
}
pthread_mutex_unlock(&m);
}
}✨Mensajes✨
int ImpresoraServer() {
Queue *q = makeQueue();
int ocupado = FALSE;
nThread t;
int *msg;
while (TRUE) {
// Si no esta ocupada, esperar
if (!ocupado) {
// esperar 5 minutos (5min * 60s * 1000ms)
msg = (int *) nReceive(&t, 60 * 5 * 1000);
if (t == NULL) {
modoBajoConsumo();
msg = (int*) nRecieve(&t,
-1); // esperar
modoUsoNormal();
}
} else { // Esperar a que se desocupe impresora
msg = (int*) nReceive(&t, -1); // esperar
if (*msg == OBTENER) {
// Encolar si esta ocupada,
if (ocupado)
put(q,t);
else { // responder si esta disponible
ocupado = TRUE;
nReply(t,0);
}
} else if (*msg == DEVOLVER) {
nReply(t, 0); // “ok, la devolviste”
if (EmptyFifoQueue(q)) {
ocupado = FALSE;
} else {
// Entregar impresora a siguiente thread
nThread *t2 = (nThread*) get(q);
nReply(t2, 0);
}
}
}
}
}Implemente:
int nSend(nThread th, void *msg)
void *nReceive(nThread *pth, int timeout_ms)
void nReply(nThread th, int rc)Esta vez con timeouts!!
Un scheduler debe:
Lo llamamos cuando usamos setReady(), suspend() o schedule().
Veamos como se implementan con prioridades
#include "nthread-impl.h"
static NthQueue *nth_pri1ReadyQueue[MAXPRI];
void nSetPriority(nThread th, int pri) {
START_CRITICAL
th->pri= pri;
schedule();
END_CRITICAL
}
static void nth_pri1SetReady(nThread th) {
CHECK_CRITICAL("nth_fcfsSetReady")
if (th->status==READY || th->status==RUN)
nFatalError("nth_fcfsReady",
"The thread was already in READY status\n");
th->status= READY;
nth_putBack(nth_pri1ReadyQueue[th->pri], th);
}
static void nth_pri1Suspend(State waitState) {
CHECK_CRITICAL("nth_fcfsSuspend")
nThread th= nSelf();
if (th->status!=RUN && th->status!=READY)
nFatalError("nth_fcfsSuspend",
"Thread was not ready or run\n");
th->status= waitState;
}#include "nthread-impl.h"
static NthQueue *nth_pri1ReadyQueue[MAXPRI];
void nSetPriority(nThread th, int pri) {
START_CRITICAL
th->pri= pri;
schedule();
END_CRITICAL
}
static void nth_pri1SetReady(nThread th) {
CHECK_CRITICAL("nth_fcfsSetReady")
if (th->status==READY || th->status==RUN)
nFatalError("nth_fcfsReady",
"The thread was already in READY status\n");
th->status= READY;
nth_putBack(nth_pri1ReadyQueue[th->pri], th);
}
static void nth_pri1Suspend(State waitState) {
CHECK_CRITICAL("nth_fcfsSuspend")
nThread th= nSelf();
if (th->status!=RUN && th->status!=READY)
nFatalError("nth_fcfsSuspend",
"Thread was not ready or run\n");
th->status= waitState;
}#include "nthread-impl.h"
static NthQueue *nth_pri1ReadyQueue[MAXPRI];
void nSetPriority(nThread th, int pri) {
START_CRITICAL
th->pri= pri;
schedule();
END_CRITICAL
}
static void nth_pri1SetReady(nThread th) {
CHECK_CRITICAL("nth_fcfsSetReady")
if (th->status==READY || th->status==RUN)
nFatalError("nth_fcfsReady",
"The thread was already in READY status\n");
th->status= READY;
nth_putBack(nth_pri1ReadyQueue[th->pri], th);
}
static void nth_pri1Suspend(State waitState) {
CHECK_CRITICAL("nth_fcfsSuspend")
nThread th= nSelf();
if (th->status!=RUN && th->status!=READY)
nFatalError("nth_fcfsSuspend",
"Thread was not ready or run\n");
th->status= waitState;
}thread#include "nthread-impl.h"
static NthQueue *nth_pri1ReadyQueue[MAXPRI];
void nSetPriority(nThread th, int pri) {
START_CRITICAL
th->pri= pri;
schedule();
END_CRITICAL
}
static void nth_pri1SetReady(nThread th) {
CHECK_CRITICAL("nth_fcfsSetReady")
if (th->status==READY || th->status==RUN)
nFatalError("nth_fcfsReady",
"The thread was already in READY status\n");
th->status= READY;
nth_putBack(nth_pri1ReadyQueue[th->pri], th);
}
static void nth_pri1Suspend(State waitState) {
CHECK_CRITICAL("nth_fcfsSuspend")
nThread th= nSelf();
if (th->status!=RUN && th->status!=READY)
nFatalError("nth_fcfsSuspend",
"Thread was not ready or run\n");
th->status= waitState;
}threadthread actual ya no sea de mejor prioridad#include "nthread-impl.h"
static NthQueue *nth_pri1ReadyQueue[MAXPRI];
void nSetPriority(nThread th, int pri) {
START_CRITICAL
th->pri= pri;
schedule();
END_CRITICAL
}
static void nth_pri1SetReady(nThread th) {
CHECK_CRITICAL("nth_fcfsSetReady")
if (th->status==READY || th->status==RUN)
nFatalError("nth_fcfsReady",
"The thread was already in READY status\n");
th->status= READY;
nth_putBack(nth_pri1ReadyQueue[th->pri], th);
}
static void nth_pri1Suspend(State waitState) {
CHECK_CRITICAL("nth_fcfsSuspend")
nThread th= nSelf();
if (th->status!=RUN && th->status!=READY)
nFatalError("nth_fcfsSuspend",
"Thread was not ready or run\n");
th->status= waitState;
}threadthread actual ya no sea de mejor prioridadthread este listo, entonces lo guardamos en su cola respectiva.#include "nthread-impl.h"
static NthQueue *nth_pri1ReadyQueue[MAXPRI];
void nSetPriority(nThread th, int pri) {
START_CRITICAL
th->pri= pri;
schedule();
END_CRITICAL
}
static void nth_pri1SetReady(nThread th) {
CHECK_CRITICAL("nth_fcfsSetReady")
if (th->status==READY || th->status==RUN)
nFatalError("nth_fcfsReady",
"The thread was already in READY status\n");
th->status= READY;
nth_putBack(nth_pri1ReadyQueue[th->pri], th);
}
static void nth_pri1Suspend(State waitState) {
CHECK_CRITICAL("nth_fcfsSuspend")
nThread th= nSelf();
if (th->status!=RUN && th->status!=READY)
nFatalError("nth_fcfsSuspend",
"Thread was not ready or run\n");
th->status= waitState;
}threadthread actual ya no sea de mejor prioridadthread este listo, entonces lo guardamos en su cola respectiva.WAIT (u otro que sea necesario)static void nth_pri1Schedule(void) {
CHECK_CRITICAL("nth_fcfsSchedule")
nThread thisTh= nSelf();
if (thisTh!=NULL && (thisTh->status==READY || thisTh->status==RUN)) {
thisTh->status= READY;
nth_putBack(nth_pri1ReadyQueue[thisTh->pri], thisTh);
}
nThread nextTh= NULL;
while (nextTh==NULL) {
int i=0;
while (i<MAXPRI) {
if (!nth_emptyQueue(nth_pri1ReadyQueue[i]))
break;
i++;
}
if (i<MAXPRI) {
nextTh= nth_getFront(nth_pri1ReadyQueue[i]);
break;
}
else {
nth_coreIsIdle[0]= 1;
sigsuspend(&nth_sigsetApp);
nth_coreIsIdle[0]= 0;
}
}
nth_changeContext(thisTh, nextTh);
nth_setSelf(thisTh);
thisTh->status= RUN;
}static void nth_pri1Schedule(void) {
CHECK_CRITICAL("nth_fcfsSchedule")
nThread thisTh= nSelf();
if (thisTh!=NULL && (thisTh->status==READY || thisTh->status==RUN)) {
thisTh->status= READY;
nth_putBack(nth_pri1ReadyQueue[thisTh->pri], thisTh);
}
nThread nextTh= NULL;
while (nextTh==NULL) {
int i=0;
while (i<MAXPRI) {
if (!nth_emptyQueue(nth_pri1ReadyQueue[i]))
break;
i++;
}
if (i<MAXPRI) {
nextTh= nth_getFront(nth_pri1ReadyQueue[i]);
break;
}
else {
nth_coreIsIdle[0]= 1;
sigsuspend(&nth_sigsetApp);
nth_coreIsIdle[0]= 0;
}
}
nth_changeContext(thisTh, nextTh);
nth_setSelf(thisTh);
thisTh->status= RUN;
}schedule() buscamos suspender el thread para darle el core al que tenga mejor prioridad.static void nth_pri1Schedule(void) {
CHECK_CRITICAL("nth_fcfsSchedule")
nThread thisTh= nSelf();
if (thisTh!=NULL && (thisTh->status==READY || thisTh->status==RUN)) {
thisTh->status= READY;
nth_putBack(nth_pri1ReadyQueue[thisTh->pri], thisTh);
}
nThread nextTh= NULL;
while (nextTh==NULL) {
int i=0;
while (i<MAXPRI) {
if (!nth_emptyQueue(nth_pri1ReadyQueue[i]))
break;
i++;
}
if (i<MAXPRI) {
nextTh= nth_getFront(nth_pri1ReadyQueue[i]);
break;
}
else {
nth_coreIsIdle[0]= 1;
sigsuspend(&nth_sigsetApp);
nth_coreIsIdle[0]= 0;
}
}
nth_changeContext(thisTh, nextTh);
nth_setSelf(thisTh);
thisTh->status= RUN;
}schedule() buscamos suspender el thread para darle el core al que tenga mejor prioridad.thread no esta suspendido (WAIT) se reincorpora a las colas de prioridades.static void nth_pri1Schedule(void) {
CHECK_CRITICAL("nth_fcfsSchedule")
nThread thisTh= nSelf();
if (thisTh!=NULL && (thisTh->status==READY || thisTh->status==RUN)) {
thisTh->status= READY;
nth_putBack(nth_pri1ReadyQueue[thisTh->pri], thisTh);
}
nThread nextTh= NULL;
while (nextTh==NULL) {
int i=0;
while (i<MAXPRI) {
if (!nth_emptyQueue(nth_pri1ReadyQueue[i]))
break;
i++;
}
if (i<MAXPRI) {
nextTh= nth_getFront(nth_pri1ReadyQueue[i]);
break;
}
else {
nth_coreIsIdle[0]= 1;
sigsuspend(&nth_sigsetApp);
nth_coreIsIdle[0]= 0;
}
}
nth_changeContext(thisTh, nextTh);
nth_setSelf(thisTh);
thisTh->status= RUN;
}schedule() buscamos suspender el thread para darle el core al que tenga mejor prioridad.thread no esta suspendido (WAIT) se reincorpora a las colas de prioridades.schedule() hasta obtener el siguiente thread.static void nth_pri1Schedule(void) {
CHECK_CRITICAL("nth_fcfsSchedule")
nThread thisTh= nSelf();
if (thisTh!=NULL && (thisTh->status==READY || thisTh->status==RUN)) {
thisTh->status= READY;
nth_putBack(nth_pri1ReadyQueue[thisTh->pri], thisTh);
}
nThread nextTh= NULL;
while (nextTh==NULL) {
int i=0;
while (i<MAXPRI) {
if (!nth_emptyQueue(nth_pri1ReadyQueue[i]))
break;
i++;
}
if (i<MAXPRI) {
nextTh= nth_getFront(nth_pri1ReadyQueue[i]);
break;
}
else {
nth_coreIsIdle[0]= 1;
sigsuspend(&nth_sigsetApp);
nth_coreIsIdle[0]= 0;
}
}
nth_changeContext(thisTh, nextTh);
nth_setSelf(thisTh);
thisTh->status= RUN;
}schedule() buscamos suspender el thread para darle el core al que tenga mejor prioridad.thread no esta suspendido (WAIT) se reincorpora a las colas de prioridades.schedule() hasta obtener el siguiente thread.static void nth_pri1Schedule(void) {
CHECK_CRITICAL("nth_fcfsSchedule")
nThread thisTh= nSelf();
if (thisTh!=NULL && (thisTh->status==READY || thisTh->status==RUN)) {
thisTh->status= READY;
nth_putBack(nth_pri1ReadyQueue[thisTh->pri], thisTh);
}
nThread nextTh= NULL;
while (nextTh==NULL) {
int i=0;
while (i<MAXPRI) {
if (!nth_emptyQueue(nth_pri1ReadyQueue[i]))
break;
i++;
}
if (i<MAXPRI) {
nextTh= nth_getFront(nth_pri1ReadyQueue[i]);
break;
}
else {
nth_coreIsIdle[0]= 1;
sigsuspend(&nth_sigsetApp);
nth_coreIsIdle[0]= 0;
}
}
nth_changeContext(thisTh, nextTh);
nth_setSelf(thisTh);
thisTh->status= RUN;
}schedule() buscamos suspender el thread para darle el core al que tenga mejor prioridad.thread no esta suspendido (WAIT) se reincorpora a las colas de prioridades.schedule() hasta obtener el siguiente thread.thread en esta.static void nth_pri1Schedule(void) {
CHECK_CRITICAL("nth_fcfsSchedule")
nThread thisTh= nSelf();
if (thisTh!=NULL && (thisTh->status==READY || thisTh->status==RUN)) {
thisTh->status= READY;
nth_putBack(nth_pri1ReadyQueue[thisTh->pri], thisTh);
}
nThread nextTh= NULL;
while (nextTh==NULL) {
int i=0;
while (i<MAXPRI) {
if (!nth_emptyQueue(nth_pri1ReadyQueue[i]))
break;
i++;
}
if (i<MAXPRI) {
nextTh= nth_getFront(nth_pri1ReadyQueue[i]);
break;
}
else {
nth_coreIsIdle[0]= 1;
sigsuspend(&nth_sigsetApp);
nth_coreIsIdle[0]= 0;
}
}
nth_changeContext(thisTh, nextTh);
nth_setSelf(thisTh);
thisTh->status= RUN;
}schedule() buscamos suspender el thread para darle el core al que tenga mejor prioridad.thread no esta suspendido (WAIT) se reincorpora a las colas de prioridades.schedule() hasta obtener el siguiente thread.thread en esta.thread.static void nth_pri1Schedule(void) {
CHECK_CRITICAL("nth_fcfsSchedule")
nThread thisTh= nSelf();
if (thisTh!=NULL && (thisTh->status==READY || thisTh->status==RUN)) {
thisTh->status= READY;
nth_putBack(nth_pri1ReadyQueue[thisTh->pri], thisTh);
}
nThread nextTh= NULL;
while (nextTh==NULL) {
int i=0;
while (i<MAXPRI) {
if (!nth_emptyQueue(nth_pri1ReadyQueue[i]))
break;
i++;
}
if (i<MAXPRI) {
nextTh= nth_getFront(nth_pri1ReadyQueue[i]);
break;
}
else {
nth_coreIsIdle[0]= 1;
sigsuspend(&nth_sigsetApp);
nth_coreIsIdle[0]= 0;
}
}
nth_changeContext(thisTh, nextTh);
nth_setSelf(thisTh);
thisTh->status= RUN;
}schedule() buscamos suspender el thread para darle el core al que tenga mejor prioridad.thread no esta suspendido (WAIT) se reincorpora a las colas de prioridades.schedule() hasta obtener el siguiente thread.thread en esta.thread.
thread que este listo para ejecutar.static void nth_pri1Schedule(void) {
CHECK_CRITICAL("nth_fcfsSchedule")
nThread thisTh= nSelf();
if (thisTh!=NULL && (thisTh->status==READY || thisTh->status==RUN)) {
thisTh->status= READY;
nth_putBack(nth_pri1ReadyQueue[thisTh->pri], thisTh);
}
nThread nextTh= NULL;
while (nextTh==NULL) {
int i=0;
while (i<MAXPRI) {
if (!nth_emptyQueue(nth_pri1ReadyQueue[i]))
break;
i++;
}
if (i<MAXPRI) {
nextTh= nth_getFront(nth_pri1ReadyQueue[i]);
break;
}
else {
nth_coreIsIdle[0]= 1;
sigsuspend(&nth_sigsetApp);
nth_coreIsIdle[0]= 0;
}
}
nth_changeContext(thisTh, nextTh);
nth_setSelf(thisTh);
thisTh->status= RUN;
}schedule() buscamos suspender el thread para darle el core al que tenga mejor prioridad.thread no esta suspendido (WAIT) se reincorpora a las colas de prioridades.schedule() hasta obtener el siguiente thread.thread en esta.thread.
thread que este listo para ejecutar.static void nth_pri1Schedule(void) {
CHECK_CRITICAL("nth_fcfsSchedule")
nThread thisTh= nSelf();
if (thisTh!=NULL && (thisTh->status==READY || thisTh->status==RUN)) {
thisTh->status= READY;
nth_putBack(nth_pri1ReadyQueue[thisTh->pri], thisTh);
}
nThread nextTh= NULL;
while (nextTh==NULL) {
int i=0;
while (i<MAXPRI) {
if (!nth_emptyQueue(nth_pri1ReadyQueue[i]))
break;
i++;
}
if (i<MAXPRI) {
nextTh= nth_getFront(nth_pri1ReadyQueue[i]);
break;
}
else {
nth_coreIsIdle[0]= 1;
sigsuspend(&nth_sigsetApp);
nth_coreIsIdle[0]= 0;
}
}
nth_changeContext(thisTh, nextTh);
nth_setSelf(thisTh);
thisTh->status= RUN;
}thread le pasamos el core correspondiente.static void nth_pri1Schedule(void) {
CHECK_CRITICAL("nth_fcfsSchedule")
nThread thisTh= nSelf();
if (thisTh!=NULL && (thisTh->status==READY || thisTh->status==RUN)) {
thisTh->status= READY;
nth_putBack(nth_pri1ReadyQueue[thisTh->pri], thisTh);
}
nThread nextTh= NULL;
while (nextTh==NULL) {
int i=0;
while (i<MAXPRI) {
if (!nth_emptyQueue(nth_pri1ReadyQueue[i]))
break;
i++;
}
if (i<MAXPRI) {
nextTh= nth_getFront(nth_pri1ReadyQueue[i]);
break;
}
else {
nth_coreIsIdle[0]= 1;
sigsuspend(&nth_sigsetApp);
nth_coreIsIdle[0]= 0;
}
}
nth_changeContext(thisTh, nextTh);
nth_setSelf(thisTh);
thisTh->status= RUN;
}thread le pasamos el core correspondiente.static void nth_pri1Schedule(void) {
CHECK_CRITICAL("nth_fcfsSchedule")
nThread thisTh= nSelf();
if (thisTh!=NULL && (thisTh->status==READY || thisTh->status==RUN)) {
thisTh->status= READY;
nth_putBack(nth_pri1ReadyQueue[thisTh->pri], thisTh);
}
nThread nextTh= NULL;
while (nextTh==NULL) {
int i=0;
while (i<MAXPRI) {
if (!nth_emptyQueue(nth_pri1ReadyQueue[i]))
break;
i++;
}
if (i<MAXPRI) {
nextTh= nth_getFront(nth_pri1ReadyQueue[i]);
break;
}
else {
nth_coreIsIdle[0]= 1;
sigsuspend(&nth_sigsetApp);
nth_coreIsIdle[0]= 0;
}
}
nth_changeContext(thisTh, nextTh);
nth_setSelf(thisTh);
thisTh->status= RUN;
}thread le pasamos el core correspondiente.thread vuelve a recibir un corestatic void nth_pri1Schedule(void) {
CHECK_CRITICAL("nth_fcfsSchedule")
nThread thisTh= nSelf();
if (thisTh!=NULL && (thisTh->status==READY || thisTh->status==RUN)) {
thisTh->status= READY;
nth_putBack(nth_pri1ReadyQueue[thisTh->pri], thisTh);
}
nThread nextTh= NULL;
while (nextTh==NULL) {
int i=0;
while (i<MAXPRI) {
if (!nth_emptyQueue(nth_pri1ReadyQueue[i]))
break;
i++;
}
if (i<MAXPRI) {
nextTh= nth_getFront(nth_pri1ReadyQueue[i]);
break;
}
else {
nth_coreIsIdle[0]= 1;
sigsuspend(&nth_sigsetApp);
nth_coreIsIdle[0]= 0;
}
}
nth_changeContext(thisTh, nextTh);
nth_setSelf(thisTh);
thisTh->status= RUN;
}thread le pasamos el core correspondiente.thread vuelve a recibir un corecore puede que sea distinto al que tenia al principiostatic void nth_pri1Schedule(void) {
CHECK_CRITICAL("nth_fcfsSchedule")
nThread thisTh= nSelf();
if (thisTh!=NULL && (thisTh->status==READY || thisTh->status==RUN)) {
thisTh->status= READY;
nth_putBack(nth_pri1ReadyQueue[thisTh->pri], thisTh);
}
nThread nextTh= NULL;
while (nextTh==NULL) {
int i=0;
while (i<MAXPRI) {
if (!nth_emptyQueue(nth_pri1ReadyQueue[i]))
break;
i++;
}
if (i<MAXPRI) {
nextTh= nth_getFront(nth_pri1ReadyQueue[i]);
break;
}
else {
nth_coreIsIdle[0]= 1;
sigsuspend(&nth_sigsetApp);
nth_coreIsIdle[0]= 0;
}
}
nth_changeContext(thisTh, nextTh);
nth_setSelf(thisTh);
thisTh->status= RUN;
}thread le pasamos el core correspondiente.thread vuelve a recibir un corecore puede que sea distinto al que tenia al principiothread.static void nth_pri1Schedule(void) {
CHECK_CRITICAL("nth_fcfsSchedule")
nThread thisTh= nSelf();
if (thisTh!=NULL && (thisTh->status==READY || thisTh->status==RUN)) {
thisTh->status= READY;
nth_putBack(nth_pri1ReadyQueue[thisTh->pri], thisTh);
}
nThread nextTh= NULL;
while (nextTh==NULL) {
int i=0;
while (i<MAXPRI) {
if (!nth_emptyQueue(nth_pri1ReadyQueue[i]))
break;
i++;
}
if (i<MAXPRI) {
nextTh= nth_getFront(nth_pri1ReadyQueue[i]);
break;
}
else {
nth_coreIsIdle[0]= 1;
sigsuspend(&nth_sigsetApp);
nth_coreIsIdle[0]= 0;
}
}
nth_changeContext(thisTh, nextTh);
nth_setSelf(thisTh);
thisTh->status= RUN;
}thread le pasamos el core correspondiente.thread vuelve a recibir un corecore puede que sea distinto al que tenia al principiothread.nSelf() retorna correctamente el thread actual.static void nth_pri1Schedule(void) {
CHECK_CRITICAL("nth_fcfsSchedule")
nThread thisTh= nSelf();
if (thisTh!=NULL && (thisTh->status==READY || thisTh->status==RUN)) {
thisTh->status= READY;
nth_putBack(nth_pri1ReadyQueue[thisTh->pri], thisTh);
}
nThread nextTh= NULL;
while (nextTh==NULL) {
int i=0;
while (i<MAXPRI) {
if (!nth_emptyQueue(nth_pri1ReadyQueue[i]))
break;
i++;
}
if (i<MAXPRI) {
nextTh= nth_getFront(nth_pri1ReadyQueue[i]);
break;
}
else {
nth_coreIsIdle[0]= 1;
sigsuspend(&nth_sigsetApp);
nth_coreIsIdle[0]= 0;
}
}
nth_changeContext(thisTh, nextTh);
nth_setSelf(thisTh);
thisTh->status= RUN;
}thread le pasamos el core correspondiente.thread vuelve a recibir un corecore puede que sea distinto al que tenia al principiothread.nSelf() retorna correctamente el thread actual.thread.static void nth_pri1Stop(void) {
CHECK_CRITICAL("nth_fcfsStop")
for (int i= 0; i<MAXPRI; i++)
nth_destroyQueue(nth_pri1ReadyQueue[i]);
}
Scheduler nth_pri1Scheduler= { .schedule = nth_pri1Schedule,
.setReady = nth_pri1SetReady,
.suspend = nth_pri1Suspend,
.stop = nth_pri1Stop };
void setPri1Scheduling() {
START_CRITICAL
if (nth_verbose)
printf("Info: setting single-core priority scheduling\n");
if (nth_totalCores!=1)
nFatalError("setPri1Scheduling",
"This priority scheduler only accepts a single core\n");
for (int i= 0; i<MAXPRI; i++)
nth_pri1ReadyQueue[i]= nth_makeQueue();
nth_setScheduler(nth_pri1Scheduler);
MapIterator *iter= getMapIterator(nth_threadSet);
void *ptr;
while (mapNext(iter, &ptr, &ptr)) {
nThread th= ptr;
if (th->status==READY)
nth_putBack(nth_pri1ReadyQueue[th->pri], th);
}
destroyMapIterator(iter);
END_CRITICAL
}
int isPri1Scheduling(void) {
return nth_scheduler.schedule==nth_pri1Scheduler.schedule;
}static void nth_pri1Stop(void) {
CHECK_CRITICAL("nth_fcfsStop")
for (int i= 0; i<MAXPRI; i++)
nth_destroyQueue(nth_pri1ReadyQueue[i]);
}
Scheduler nth_pri1Scheduler= { .schedule = nth_pri1Schedule,
.setReady = nth_pri1SetReady,
.suspend = nth_pri1Suspend,
.stop = nth_pri1Stop };
void setPri1Scheduling() {
START_CRITICAL
if (nth_verbose)
printf("Info: setting single-core priority scheduling\n");
if (nth_totalCores!=1)
nFatalError("setPri1Scheduling",
"This priority scheduler only accepts a single core\n");
for (int i= 0; i<MAXPRI; i++)
nth_pri1ReadyQueue[i]= nth_makeQueue();
nth_setScheduler(nth_pri1Scheduler);
MapIterator *iter= getMapIterator(nth_threadSet);
void *ptr;
while (mapNext(iter, &ptr, &ptr)) {
nThread th= ptr;
if (th->status==READY)
nth_putBack(nth_pri1ReadyQueue[th->pri], th);
}
destroyMapIterator(iter);
END_CRITICAL
}
int isPri1Scheduling(void) {
return nth_scheduler.schedule==nth_pri1Scheduler.schedule;
}static void nth_pri1Stop(void) {
CHECK_CRITICAL("nth_fcfsStop")
for (int i= 0; i<MAXPRI; i++)
nth_destroyQueue(nth_pri1ReadyQueue[i]);
}
Scheduler nth_pri1Scheduler= { .schedule = nth_pri1Schedule,
.setReady = nth_pri1SetReady,
.suspend = nth_pri1Suspend,
.stop = nth_pri1Stop };
void setPri1Scheduling() {
START_CRITICAL
if (nth_verbose)
printf("Info: setting single-core priority scheduling\n");
if (nth_totalCores!=1)
nFatalError("setPri1Scheduling",
"This priority scheduler only accepts a single core\n");
for (int i= 0; i<MAXPRI; i++)
nth_pri1ReadyQueue[i]= nth_makeQueue();
nth_setScheduler(nth_pri1Scheduler);
MapIterator *iter= getMapIterator(nth_threadSet);
void *ptr;
while (mapNext(iter, &ptr, &ptr)) {
nThread th= ptr;
if (th->status==READY)
nth_putBack(nth_pri1ReadyQueue[th->pri], th);
}
destroyMapIterator(iter);
END_CRITICAL
}
int isPri1Scheduling(void) {
return nth_scheduler.schedule==nth_pri1Scheduler.schedule;
}static void nth_pri1Stop(void) {
CHECK_CRITICAL("nth_fcfsStop")
for (int i= 0; i<MAXPRI; i++)
nth_destroyQueue(nth_pri1ReadyQueue[i]);
}
Scheduler nth_pri1Scheduler= { .schedule = nth_pri1Schedule,
.setReady = nth_pri1SetReady,
.suspend = nth_pri1Suspend,
.stop = nth_pri1Stop };
void setPri1Scheduling() {
START_CRITICAL
if (nth_verbose)
printf("Info: setting single-core priority scheduling\n");
if (nth_totalCores!=1)
nFatalError("setPri1Scheduling",
"This priority scheduler only accepts a single core\n");
for (int i= 0; i<MAXPRI; i++)
nth_pri1ReadyQueue[i]= nth_makeQueue();
nth_setScheduler(nth_pri1Scheduler);
MapIterator *iter= getMapIterator(nth_threadSet);
void *ptr;
while (mapNext(iter, &ptr, &ptr)) {
nThread th= ptr;
if (th->status==READY)
nth_putBack(nth_pri1ReadyQueue[th->pri], th);
}
destroyMapIterator(iter);
END_CRITICAL
}
int isPri1Scheduling(void) {
return nth_scheduler.schedule==nth_pri1Scheduler.schedule;
}static void nth_pri1Stop(void) {
CHECK_CRITICAL("nth_fcfsStop")
for (int i= 0; i<MAXPRI; i++)
nth_destroyQueue(nth_pri1ReadyQueue[i]);
}
Scheduler nth_pri1Scheduler= { .schedule = nth_pri1Schedule,
.setReady = nth_pri1SetReady,
.suspend = nth_pri1Suspend,
.stop = nth_pri1Stop };
void setPri1Scheduling() {
START_CRITICAL
if (nth_verbose)
printf("Info: setting single-core priority scheduling\n");
if (nth_totalCores!=1)
nFatalError("setPri1Scheduling",
"This priority scheduler only accepts a single core\n");
for (int i= 0; i<MAXPRI; i++)
nth_pri1ReadyQueue[i]= nth_makeQueue();
nth_setScheduler(nth_pri1Scheduler);
MapIterator *iter= getMapIterator(nth_threadSet);
void *ptr;
while (mapNext(iter, &ptr, &ptr)) {
nThread th= ptr;
if (th->status==READY)
nth_putBack(nth_pri1ReadyQueue[th->pri], th);
}
destroyMapIterator(iter);
END_CRITICAL
}
int isPri1Scheduling(void) {
return nth_scheduler.schedule==nth_pri1Scheduler.schedule;
}static void nth_pri1Stop(void) {
CHECK_CRITICAL("nth_fcfsStop")
for (int i= 0; i<MAXPRI; i++)
nth_destroyQueue(nth_pri1ReadyQueue[i]);
}
Scheduler nth_pri1Scheduler= { .schedule = nth_pri1Schedule,
.setReady = nth_pri1SetReady,
.suspend = nth_pri1Suspend,
.stop = nth_pri1Stop };
void setPri1Scheduling() {
START_CRITICAL
if (nth_verbose)
printf("Info: setting single-core priority scheduling\n");
if (nth_totalCores!=1)
nFatalError("setPri1Scheduling",
"This priority scheduler only accepts a single core\n");
for (int i= 0; i<MAXPRI; i++)
nth_pri1ReadyQueue[i]= nth_makeQueue();
nth_setScheduler(nth_pri1Scheduler);
MapIterator *iter= getMapIterator(nth_threadSet);
void *ptr;
while (mapNext(iter, &ptr, &ptr)) {
nThread th= ptr;
if (th->status==READY)
nth_putBack(nth_pri1ReadyQueue[th->pri], th);
}
destroyMapIterator(iter);
END_CRITICAL
}
int isPri1Scheduling(void) {
return nth_scheduler.schedule==nth_pri1Scheduler.schedule;
}threads y colocarlos en la cola adecuadastatic void nth_pri1Stop(void) {
CHECK_CRITICAL("nth_fcfsStop")
for (int i= 0; i<MAXPRI; i++)
nth_destroyQueue(nth_pri1ReadyQueue[i]);
}
Scheduler nth_pri1Scheduler= { .schedule = nth_pri1Schedule,
.setReady = nth_pri1SetReady,
.suspend = nth_pri1Suspend,
.stop = nth_pri1Stop };
void setPri1Scheduling() {
START_CRITICAL
if (nth_verbose)
printf("Info: setting single-core priority scheduling\n");
if (nth_totalCores!=1)
nFatalError("setPri1Scheduling",
"This priority scheduler only accepts a single core\n");
for (int i= 0; i<MAXPRI; i++)
nth_pri1ReadyQueue[i]= nth_makeQueue();
nth_setScheduler(nth_pri1Scheduler);
MapIterator *iter= getMapIterator(nth_threadSet);
void *ptr;
while (mapNext(iter, &ptr, &ptr)) {
nThread th= ptr;
if (th->status==READY)
nth_putBack(nth_pri1ReadyQueue[th->pri], th);
}
destroyMapIterator(iter);
END_CRITICAL
}
int isPri1Scheduling(void) {
return nth_scheduler.schedule==nth_pri1Scheduler.schedule;
}threads y colocarlos en la cola adecuadastatic void nth_pri1Stop(void) {
CHECK_CRITICAL("nth_fcfsStop")
for (int i= 0; i<MAXPRI; i++)
nth_destroyQueue(nth_pri1ReadyQueue[i]);
}
Scheduler nth_pri1Scheduler= { .schedule = nth_pri1Schedule,
.setReady = nth_pri1SetReady,
.suspend = nth_pri1Suspend,
.stop = nth_pri1Stop };
void setPri1Scheduling() {
START_CRITICAL
if (nth_verbose)
printf("Info: setting single-core priority scheduling\n");
if (nth_totalCores!=1)
nFatalError("setPri1Scheduling",
"This priority scheduler only accepts a single core\n");
for (int i= 0; i<MAXPRI; i++)
nth_pri1ReadyQueue[i]= nth_makeQueue();
nth_setScheduler(nth_pri1Scheduler);
MapIterator *iter= getMapIterator(nth_threadSet);
void *ptr;
while (mapNext(iter, &ptr, &ptr)) {
nThread th= ptr;
if (th->status==READY)
nth_putBack(nth_pri1ReadyQueue[th->pri], th);
}
destroyMapIterator(iter);
END_CRITICAL
}
int isPri1Scheduling(void) {
return nth_scheduler.schedule==nth_pri1Scheduler.schedule;
}threads y colocarlos en la cola adecuadastatic void nth_pri1Stop(void) {
CHECK_CRITICAL("nth_fcfsStop")
for (int i= 0; i<MAXPRI; i++)
nth_destroyQueue(nth_pri1ReadyQueue[i]);
}
Scheduler nth_pri1Scheduler= { .schedule = nth_pri1Schedule,
.setReady = nth_pri1SetReady,
.suspend = nth_pri1Suspend,
.stop = nth_pri1Stop };
void setPri1Scheduling() {
START_CRITICAL
if (nth_verbose)
printf("Info: setting single-core priority scheduling\n");
if (nth_totalCores!=1)
nFatalError("setPri1Scheduling",
"This priority scheduler only accepts a single core\n");
for (int i= 0; i<MAXPRI; i++)
nth_pri1ReadyQueue[i]= nth_makeQueue();
nth_setScheduler(nth_pri1Scheduler);
MapIterator *iter= getMapIterator(nth_threadSet);
void *ptr;
while (mapNext(iter, &ptr, &ptr)) {
nThread th= ptr;
if (th->status==READY)
nth_putBack(nth_pri1ReadyQueue[th->pri], th);
}
destroyMapIterator(iter);
END_CRITICAL
}
int isPri1Scheduling(void) {
return nth_scheduler.schedule==nth_pri1Scheduler.schedule;
}threads y colocarlos en la cola adecuadaCC4302 — Sistemas Operativos