int P4_Startup(void *notused) { int pid; USLOSS_Console("P4_Startup\n"); int result = Sys_Spawn("P5_Startup", P5_Startup, NULL, 4 * USLOSS_MIN_STACK, 4, &pid); Sys_Wait(&pid,&result); printf("P4 pid changed: %d\n", pid); USLOSS_Console("P4_Finished\n"); return 0; }
int P3_Startup(void *notused) { int pid; USLOSS_Console("P3_Startup\n"); int result = Sys_Spawn("P4_Startup", P4_Startup, NULL, 4 * USLOSS_MIN_STACK, 3, &pid); printf("P3 pid changedi(P4 pid): %d\n", pid); Sys_Wait(&pid, &result); Sys_DumpProcesses(); USLOSS_Console("P3_Finished\n"); return 0; }
int P6_Startup(void *notused) { int pid; USLOSS_Console("P6_Startup\n"); int result = Sys_Spawn("P7_Startup", P7_Startup, NULL, 4 * USLOSS_MIN_STACK, 5, &pid); assert(result == 0); Sys_Wait(&pid,&result); int status = 4; Sys_Terminate(status); USLOSS_Console("P6_Finished\n"); return 0; }
int P4_Startup(void *arg) { int i; int rc; int pid; int child; int numChildren = sizeof(names) / sizeof(char *); USLOSS_Console("P4_Startup starting.\n"); rc = Sys_VmInit(PAGES, PAGES, numChildren * PAGES, 1, (void **) &vmRegion); if (rc != 0) { USLOSS_Console("Sys_VmInit failed: %d\n", rc); USLOSS_Halt(1); } pageSize = USLOSS_MmuPageSize(); for (i = 0; i < numChildren; i++) { rc = Sys_Spawn(names[i], Child, (void *) names[i], USLOSS_MIN_STACK * 2, 2, &pid); assert(rc == 0); } for (i = 0; i < numChildren; i++) { rc = Sys_Wait(&pid, &child); assert(rc == 0); } for (i = 0; i < numChildren; i++) { rc = Sys_Spawn(names[i], Child, (void *) names[i], USLOSS_MIN_STACK * 2, 2, &pid); assert(rc == 0); } for (i = 0; i < numChildren; i++) { rc = Sys_Wait(&pid, &child); assert(rc == 0); } Sys_VmDestroy(); USLOSS_Console("P4_Startup done.\n"); return 0; }
int P3_Startup(void *arg) { // Test 1 USLOSS_Console("Testing usage of semaphore\n"); USLOSS_Console("------------------------\n"); USLOSS_Console("Testing P3_Startup by itself\n"); int semaphore; // Necessary only because of args specified by function prototype int handle = Sys_SemCreate(1, &semaphore); assert(semaphore >= 0); assert(handle == 0); USLOSS_Console("Semaphore created with initial value 1\n"); int result = Sys_SemP(semaphore); assert(result == 0); USLOSS_Console("P3_Startup clears P on semaphore\n"); result = Sys_SemV(semaphore); assert(result == 0); USLOSS_Console("P3_Startup V's semaphore\n"); USLOSS_Console("Test cleared!\n"); USLOSS_Console("------------------------\n"); // Test 2 // Note that spawned proc has higher priority than P3_Startup // to ensure that it P's and V's on the same semaphore USLOSS_Console("Testing P3_Startup on mutex with another proc\n"); int pid; result = Sys_Spawn("PatientProc1", PatientProc1, (void *) &semaphore, USLOSS_MIN_STACK, 2, &pid); assert(pid != -1); assert(result == 0); result = Sys_SemP(semaphore); assert(result == 0); USLOSS_Console("P3_Startup clears P on semaphore again\n"); result = Sys_SemV(semaphore); assert(result == 0); USLOSS_Console("P3_Startup V's semaphore\n"); USLOSS_Console("Test cleared!\n"); USLOSS_Console("------------------------\n"); // Test 3 USLOSS_Console("Testing P3_Startup on semaphore with initial value 2 with another proc\n"); handle = Sys_SemCreate(2, &semaphore); assert(semaphore >= 0); assert(handle == 0); USLOSS_Console("Semaphore created with initial value 2\n"); result = Sys_Spawn("PatientProc2", PatientProc2, (void *) &semaphore, USLOSS_MIN_STACK, 2, &pid); assert(pid != -1); assert(result == 0); result = Sys_SemP(semaphore); assert(result == 0); USLOSS_Console("P3_Startup clears P on semaphore with initial value 2\n"); result = Sys_SemV(semaphore); result = Sys_SemV(semaphore); assert(result == 0); USLOSS_Console("P3_Startup V's semaphore with initial value 2 twice\n"); USLOSS_Console("Test cleared!\n"); USLOSS_Console("------------------------\n"); USLOSS_Console("You passed the test! Treat yourself to a cookie!\n"); return 7; }