int main(int argc, char *argv[]) { int id0, id1; int i; id0 = mcreate(0, func0, (void *)&i); id1 = mcreate(1, func1, (void *)&i); printf("Eu sou a main após a criação de ID0 e ID1\n"); mwait(id0); mwait(id1); printf("Eu sou a main voltando para terminar o programa\n"); }
int main(int argc, char *argv[]) { int id0, id1, id2; int i; id0 = mcreate(0, func0, (void *)&i); id1 = mcreate(0, func1, (void *)&i); id2 = mcreate(0, func1, (void *)&i); printf("Eu sou a main após a criação de tid=%d e tid=%d e tid=%d\n",id0,id1,id2); myield(); printf("Eu sou a main voltando para terminar o programa\n"); }
int main (int argc, char *argv[]) { int id0, id1; int i; id0 = mcreate(0, func0, (void *)&i); id1 = mcreate(1, func1, (void *)&i); printf("Eu sou a main após a criação de ID0 e ID1, %d\n", (sizeOf(ready1) + sizeOf(ready0) + sizeOf(ready2) + sizeOf(blockedThreads))); mwait(id0); mwait(id1); printf("Eu sou a main voltando para terminar o programa\n"); }
int main() { int x = 0; mcreate(0, func0, (void *) &x); x++; printf("Sou a main após criar a thread 0, com x = %d\n", x); myield(); mcreate(0, func1, (void *) &x); x++; myield(); x++; myield(); exit(0); }
void init_messages(void) { char *cmd; MESG * md; (void) signal(SIGPIPE, SIG_IGN); calculate_nopen (); Message = (char *)Malloc(MSGMAX); (void) Chmod(Lp_Tmp, 0711); if ((md = mcreate(Lp_FIFO)) == NULL) fail ("Can't create public message device (%s).\n", PERROR); mon_discon(md, conn_shutdown); if (mlisteninit(md) != 0) if (errno == ENOMEM) mallocfail(); else fail ("Unexpected streams error (%s).\n" , PERROR); (void) Chmod(Lp_FIFO, 0666); return; }
int main(int argc, char *argv[]) { int id0, id1; int i; /* Código de execução */ id0 = mcreate(func0, (void *)&i); id1 = mcreate(func1, (void *)&i); /* Código de execução */ mjoin(id0); mjoin(id1); return 0; }
int main() { thdata data1, data2; /* structs to be passed to threads */ int thread1, thread2; /* initialize data to pass to thread 1 */ data1.thread_no = 1; strcpy(data1.message, "Hello!"); /* initialize data to pass to thread 2 */ data2.thread_no = 2; strcpy(data2.message, "Hi!"); /* create threads 1 and 2 */ thread1 = mcreate ((void *) &print_message_function, (void *) &data1); if (thread1 == -1) { printf("Error creating thread 1, exiting...\n"); exit(70); //error code for internal software error } thread2 = mcreate ((void *) &print_message_function, (void *) &data2); if (thread2 == -1) { printf("Error creating thread 2, exiting...\n"); exit(70); } /* Main block now waits for both threads to terminate, before it exits If main block exits, both threads exit, even if the threads have not finished their work */ if (mjoin(thread1) == -1) { printf("Error syncing thread 1, exiting...\n"); exit(70); } if ( mjoin(thread2) == -1) { printf("Error syncing thread 2, exiting...\n"); exit(70); } /* exit */ printf ("Perfect execution, now exiting normally...\n"); exit(0); } /* main() */
int msend(char *data){ message *m = 0; mcreate(&m); cprintf("\nID -> %d\n", m->id); return 0; }
int main() { int x = 150, i; i = mcreate(0, func0, (void *) &x); printf("Sou a main após criar a thread 0\n"); mwait(i); i = mcreate(-1, func1, (void *) &x); if(i == -1){ printf("Sou a main e não consegui criar uma nova thread! "); printf("A prioridade que passei era inválida.\n"); } else exit(0); i = mcreate(1, func1, (void *) &x); printf("Sou a main após criar a thread 1\n"); mwait(i); exit(0); }
void *func1(void *arg) { int i; printf("Sou a thread 1 imprimindo %d\n", *((int *) arg)); i = mcreate(0, func2, NULL); if(i != -1) printf("Sou a thread 1 e consegui criar uma nova thread!\n"); else exit(0); mwait(i); return NULL; }
int main() { int i; thread_t t[N_THREADS]; mmutex_init(&mutex); printf("munlock executado antes de iniciar escalonador retorna %d.\n", munlock(&mutex)); printf("Main criando %d threads...\n", N_THREADS); for (i = 0; i < N_THREADS; i++) { t[i].prio = 1; t[i].id = mcreate(1, (void *(*)(void*)) &print_thread_mutex, &t[i]); } printf("munlock executado com mutex livre retorna %d\n", munlock(&mutex)); printf("Main esperando as threads...\n"); for (i = 0; i < N_THREADS; i++) { mwait(t[i].id); } printf("Fim da funcao main...\n"); return 0; }
int main () { int ids[MAX_THREADS]; int i = 0; puts ("Started."); mmutex_init(&mutex); for (i=0; i < MAX_THREADS; i++) { ids[i] = mcreate(2,&makeWork, NULL); printf("Thread using TID %d started working...\n", ids[i]); } for (i=0; i < MAX_THREADS; i++) { mwait(ids[i]); printf("Thread using TID %d finished.\n", ids[i]); } exit(0); }
int main(int argc, char *argv[]) { int i, pid[MAX_THR]; for (i = 0; i < MAX_THR; i++) { pid[i] = mcreate(1, func, (void *)('A'+i)); if ( pid[i] == -1) { printf("ERRO: criação de thread!\n"); exit(-1); } } for (i = 0; i < MAX_THR; i++) mwait(pid[i]); for (i = 0; i < MAX_SIZE; i++) { if ( (i % 20) == 0 ) printf("\n"); printf("%c", (char)vetor[i]); } printf("\nConcluido vetor de letras...\n"); exit(0); }
int main(int arg, char **argcv){ int nT=10; int *threads = (int*)malloc(nT*sizeof(int)); int i; int n=0; if(threads==NULL) return 0; for(i=0;i<nT;i++){ threads[i]=mcreate(i%2, (void*)doSomething, &n); } mwait(3); printf("\nEnd of main...\n"); return 0; }
State * superHnewstate(Engine *E, double xloc, double yloc, double zloc, char *trajfilename) { int i; State *S; char *logfilename; S = (State *)mcalloc(E, 1, sizeof(State), "(State *)S"); if (S == NULL) { mexit(E, "Failed to allocate memory for State *S.", -1); } S->superH = (SuperHState *)mcalloc(E, 1, sizeof(SuperHState), "S->superH"); if (S->superH == NULL) { mexit(E, "Failed to allocate memory for S->superH.", -1); } S->MEM = (uchar *)mcalloc(E, 1, DEFLT_MEMSIZE, "(uchar *)S->MEM"); if (S->MEM == NULL) { mexit(E, "Failed to allocate memory for S->MEM.", -1); } S->superH->B = (SuperHBuses *)mcalloc(E, 1, sizeof(SuperHBuses), "(SuperHBuses *)S->superH->B"); if (S->superH->B == NULL) { mexit(E, "Failed to allocate memory for S->superH->B.", -1); } S->N = (Numa *)mcalloc(E, 1, sizeof(Numa), "(Numa *)S->N"); if (S->N == NULL) { mexit(E, "Failed to allocate memory for S->N.", -1); } S->N->count = 0; /* Actual entries are allocated when a region is installed */ S->N->regions = (Numaregion **)mcalloc(E, MAX_NUMA_REGIONS, sizeof(Numaregion*), "(Numaregion **)S->N->regions"); if (S->N->regions == NULL) { mexit(E, "Failed to allocate memory for S->N->regions.", -1); } S->Nstack = (Numa *)mcalloc(E, 1, sizeof(Numa), "(Numa *)S->Nstack"); if (S->Nstack == NULL) { mexit(E, "Failed to allocate memory for S->Nstack.", -1); } S->Nstack->count = 0; /* Actual entries are allocated when a region is installed */ S->Nstack->regions = (Numaregion **)mcalloc(E, MAX_NUMA_REGIONS, sizeof(Numaregion*), "(Numaregion **)S->Nstack->regions"); if (S->Nstack->regions == NULL) { mexit(E, "Failed to allocate memory for S->Nstack->regions.", -1); } S->RT = (Regtraces *)mcalloc(E, 1, sizeof(Regtraces), "(Regtraces *)S->RT"); if (S->RT == NULL) { mexit(E, "Failed to allocate memory for S->RT.", -1); } S->RT->count = 0; /* Actual entries are allocated when a region is installed */ S->RT->regvts = (Regvt **)mcalloc(E, MAX_REG_TRACERS, sizeof(Regvt*), "(Regvt **)S->RT->regvts"); if (S->RT->regvts == NULL) { mexit(E, "Failed to allocate memory for S->RT->regvts.", -1); } if (SF_SIMLOG) { logfilename = (char *)mcalloc(E, 1, MAX_NAMELEN*sizeof(char), "logfilename in machine-hitachi-sh.c"); if (logfilename == NULL) { mexit(E, "Failed to allocate memory for logfilename.", -1); } msnprint(logfilename, MAX_NAMELEN, "simlog.node%d", E->nnodes); S->logfd = mcreate(logfilename, M_OWRITE|M_OTRUNCATE); mfree(E, logfilename, "char * logfilename in machine-hitachi-sh.c"); if (S->logfd < 0) { mexit(E, "Could not open logfile for writing.", -1); } } E->cp = S; E->sp[E->nnodes] = S; mprint(E, NULL, siminfo, "New node created with node ID %d\n", E->nnodes); /* Update the min cycle time */ E->mincycpsec = PICOSEC_MAX; E->maxcycpsec = 0; for (i = 0; i < E->nnodes; i++) { E->mincycpsec = min(E->mincycpsec, E->sp[i]->CYCLETIME); E->maxcycpsec = max(E->maxcycpsec, E->sp[i]->CYCLETIME); } S->dumpregs = superHdumpregs; S->dumpsysregs = superHdumpsysregs; S->fatalaction = superHfatalaction; S->stallaction = superHstallaction; S->settimerintrdelay = superHsettimerintrdelay; S->take_nic_intr = superHtake_nic_intr; S->take_timer_intr = superHtake_timer_intr; S->take_batt_intr = superHtake_batt_intr; S->check_batt_intr = superHcheck_batt_intr; S->check_nic_intr = superHcheck_nic_intr; S->cache_init = superHcache_init; S->resetcpu = superHresetcpu; S->step = superHstep; S->cyclestep = superHstep; S->faststep = superHfaststep; S->dumppipe = superHdumppipe; S->pipeflush = superHpipeflush; /* Most of the device registers are SH7708 specific */ S->devreadbyte = dev7708readbyte; S->devreadword = dev7708readword; S->devreadlong = dev7708readlong; S->devwritebyte = dev7708writebyte; S->devwriteword = dev7708writeword; S->devwritelong = dev7708writelong; S->split = superHsplit; S->vmtranslate = superHvmtranslate; S->dumptlb = superHdumptlb; S->cache_deactivate = superHcache_deactivate; S->cache_printstats = superHcache_printstats; S->writebyte = superHwritebyte; S->xloc = xloc; S->yloc = yloc; S->zloc = zloc; if (trajfilename != NULL) { S->trajfilename = (char *)mcalloc(E, 1, strlen(trajfilename)+1, "S->trajfilename in "SF_FILE_MACRO); if (S->trajfilename == nil) { mexit(E, "mcalloc failed for S->trajfilename in "SF_FILE_MACRO, -1); } strcpy(S->trajfilename, trajfilename); } S->NODE_ID = E->baseid + E->nnodes; /* Must know correct number of nodes in resetcpu() */ E->nnodes++; S->resetcpu(E, S); S->superH->nicintrQ = (InterruptQ *)mcalloc(E, 1, sizeof(InterruptQ), "InterruptQ *nicintrQ in superHnewstate()"); if (S->superH->nicintrQ == NULL) { mexit(E, "Failed to allocate memory for InterruptQ *nicintrQ in superHnewstate().", -1); } S->superH->nicintrQ->hd = (Interrupt *)mcalloc(E, 1, sizeof(Interrupt), "Interrupt *S->superH->nicintrQ->hd in superHnewstate()"); S->superH->nicintrQ->tl = (Interrupt *)mcalloc(E, 1, sizeof(Interrupt), "Interrupt *S->superH->nicintrQ->tl in superHnewstate()"); if (S->superH->nicintrQ->hd == NULL || S->superH->nicintrQ->tl == NULL) { mexit(E, "Failed to allocate memory for S->superH->nicintrQ->hd | S->superH->nicintrQ->tl.", -1); } S->superH->excpQ = (InterruptQ *)mcalloc(E, 1, sizeof(InterruptQ), "InterruptQ *excpQ in superHnewstate()"); if (S->superH->excpQ == NULL) { mexit(E, "Failed to allocate memory for InterruptQ *excpQ in superHnewstate().", -1); } S->superH->excpQ->hd = (Interrupt *)mcalloc(E, 1, sizeof(Interrupt), "Interrupt *S->superH->excpQ->hd in superHnewstate()"); S->superH->excpQ->tl = (Interrupt *)mcalloc(E, 1, sizeof(Interrupt), "Interrupt *S->superH->excpQ->tl in superHnewstate()"); if (S->superH->excpQ->hd == NULL || S->superH->excpQ->tl == NULL) { mexit(E, "Failed to allocate memory for S->superH->excpQ->hd | S->superH->excpQ->tl.", -1); } return S; }