From 3b2267123d4f1418c1812fb14e1ddb3329277acd Mon Sep 17 00:00:00 2001 From: Geoffrey Challen Date: Thu, 31 Dec 2015 14:53:16 -0500 Subject: [PATCH] Synchronization driver problem changes. --- kern/synchprobs/stoplight.c | 37 +++++++++++--------- kern/test/synchprobs.c | 69 +++++++++++-------------------------- 2 files changed, 40 insertions(+), 66 deletions(-) diff --git a/kern/synchprobs/stoplight.c b/kern/synchprobs/stoplight.c index 15ad3c9..8cf2cc6 100644 --- a/kern/synchprobs/stoplight.c +++ b/kern/synchprobs/stoplight.c @@ -28,30 +28,33 @@ */ /* - * Driver code is in kern/tests/synchprobs.c We will - * replace that file. This file is yours to modify as you see fit. + * Driver code is in kern/tests/synchprobs.c We will replace that file. This + * file is yours to modify as you see fit. * * You should implement your solution to the stoplight problem below. The - * quadrant and direction mappings for reference: (although the problem is, - * of course, stable under rotation) + * quadrant and direction mappings for reference: (although the problem is, of + * course, stable under rotation) * * | 0 | - * -- -- - * 0 1 - * 3 1 - * 3 2 - * -- -- - * | 2 | + * -- -- 0 1 3 1 3 2 + * -- -- | 2 | * * As way to think about it, assuming cars drive on the right: a car entering - * the intersection from direction X will enter intersection quadrant X - * first. + * the intersection from direction X will enter intersection quadrant X first. + * The semantics of the problem are that once a car enters any quadrant it has + * to be somewhere in the intersection until it call leaveIntersection(), + * which it should call while in the final quadrant. * - * You will probably want to write some helper functions to assist - * with the mappings. Modular arithmetic can help, e.g. a car passing - * straight through the intersection entering from direction X will leave to - * direction (X + 2) % 4 and pass through quadrants X and (X + 3) % 4. - * Boo-yah. + * As an example, let's say a car approaches the intersection and needs to + * pass through quadrants 0, 3 and 2. Once you call inQuadrant(0), the car is + * considered in quadrant 0 until you call inQuadrant(3). After you call + * inQuadrant(2), the car is considered in quadrant 2 until you call + * leaveIntersection(). + * + * You will probably want to write some helper functions to assist with the + * mappings. Modular arithmetic can help, e.g. a car passing straight through + * the intersection entering from direction X will leave to direction (X + 2) + * % 4 and pass through quadrants X and (X + 3) % 4. Boo-yah. * * Your solutions below should call the inQuadrant() and leaveIntersection() * functions in synchprobs.c to record their progress. diff --git a/kern/test/synchprobs.c b/kern/test/synchprobs.c index 5942e88..9917578 100644 --- a/kern/test/synchprobs.c +++ b/kern/test/synchprobs.c @@ -1,8 +1,8 @@ /* - * 08 Feb 2012 : GWA : Please make any changes necessary to test your code to - * the drivers in this file. However, the automated testing suite *will - * replace this file in its entirety* with driver code intented to stress - * test your synchronization problem solutions. + * NO NOT MODIFY THIS FILE + * + * All the contents of this file are overwritten during automated + * testing. Please consider this before changing anything in this file. */ #include @@ -17,50 +17,39 @@ #define PROBLEMS_MAX_SPINNER 8192 /* - * 08 Feb 2012 : GWA : Driver code for the whalemating problem. - */ - -/* - * 08 Feb 2012 : GWA : The following functions are for you to use when each - * whale starts and completes either mating (if it is a male or female) or - * matchmaking. We will use the output from these functions to verify the to - * verify the correctness of your solution. These functions may spin for - * arbitrary periods of time or yield. + * Driver code for the whalemating problem. */ inline void male_start(void) { random_yielder(PROBLEMS_MAX_YIELDER); - kprintf("%s starting\n", curthread->t_name); + random_spinner(PROBLEMS_MAX_SPINNER); + tkprintf("%s starting\n", curthread->t_name); } inline void male_end(void) { - kprintf("%s ending\n", curthread->t_name); + tkprintf("%s ending\n", curthread->t_name); } inline void female_start(void) { random_spinner(PROBLEMS_MAX_SPINNER); - kprintf("%s starting\n", curthread->t_name); + random_yielder(PROBLEMS_MAX_YIELDER); + tkprintf("%s starting\n", curthread->t_name); } inline void female_end(void) { - kprintf("%s ending\n", curthread->t_name); + tkprintf("%s ending\n", curthread->t_name); } inline void matchmaker_start(void) { random_yielder(PROBLEMS_MAX_YIELDER); - kprintf("%s starting\n", curthread->t_name); + random_spinner(PROBLEMS_MAX_SPINNER); + tkprintf("%s starting\n", curthread->t_name); } inline void matchmaker_end(void) { - kprintf("%s ending\n", curthread->t_name); + tkprintf("%s ending\n", curthread->t_name); } -/* - * 08 Feb 2012 : GWA : The following function drives the entire whalemating - * process. Feel free to modify at will, but make no assumptions about the - * order or timing of threads launched by our testing suite. - */ - #define NMATING 10 struct semaphore * whalematingMenuSemaphore; @@ -72,8 +61,7 @@ int whalemating(int nargs, char **args) { int i, j, err = 0; char name[32]; - whalematingMenuSemaphore = sem_create("Whalemating Driver Semaphore", - 0); + whalematingMenuSemaphore = sem_create("Whalemating Driver Semaphore", 0); if (whalematingMenuSemaphore == NULL ) { panic("whalemating: sem_create failed.\n"); } @@ -118,37 +106,20 @@ int whalemating(int nargs, char **args) { } /* - * 08 Feb 2012 : GWA : Driver code for the stoplight problem. - */ - -/* - * 08 Feb 2012 : GWA : The following functions should be called by your - * stoplight solution when a car is in an intersection quadrant. The - * semantics of the problem are that once a car enters any quadrant it has to - * be somewhere in the intersection until it call leaveIntersection(), which - * it should call while in the final quadrant. - * - * As an example, let's say a car approaches the intersection and needs to - * pass through quadrants 0, 3 and 2. Once you call inQuadrant(0), the car is - * considered in quadrant 0 until you call inQuadrant(3). After you call - * inQuadrant(2), the car is considered in quadrant 2 until you call - * leaveIntersection(). - * - * As in the whalemating example, we will use the output from these functions - * to verify the correctness of your solution. These functions may spin for - * arbitrary periods of time or yield. + * Driver code for the stoplight problem. */ inline void inQuadrant(int quadrant) { random_spinner(PROBLEMS_MAX_SPINNER); - kprintf("%s in quadrant %d\n", curthread->t_name, quadrant); + random_yielder(PROBLEMS_MAX_YIELDER); + tkprintf("%s in quadrant %d\n", curthread->t_name, quadrant); } inline void leaveIntersection() { - kprintf("%s left the intersection\n", curthread->t_name); + tkprintf("%s left the intersection\n", curthread->t_name); } -#define NCARS 99 +#define NCARS 32 struct semaphore * stoplightMenuSemaphore;