Synchronization driver problem changes.

This commit is contained in:
Geoffrey Challen 2015-12-31 14:53:16 -05:00
parent 2e721daedf
commit 3b2267123d
2 changed files with 40 additions and 66 deletions

View File

@ -28,30 +28,33 @@
*/ */
/* /*
* Driver code is in kern/tests/synchprobs.c We will * Driver code is in kern/tests/synchprobs.c We will replace that file. This
* replace that file. This file is yours to modify as you see fit. * file is yours to modify as you see fit.
* *
* You should implement your solution to the stoplight problem below. The * You should implement your solution to the stoplight problem below. The
* quadrant and direction mappings for reference: (although the problem is, * quadrant and direction mappings for reference: (although the problem is, of
* of course, stable under rotation) * course, stable under rotation)
* *
* | 0 | * | 0 |
* -- -- * -- -- 0 1 3 1 3 2
* 0 1 * -- -- | 2 |
* 3 1
* 3 2
* -- --
* | 2 |
* *
* As way to think about it, assuming cars drive on the right: a car entering * 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 * the intersection from direction X will enter intersection quadrant X first.
* 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 * As an example, let's say a car approaches the intersection and needs to
* with the mappings. Modular arithmetic can help, e.g. a car passing * pass through quadrants 0, 3 and 2. Once you call inQuadrant(0), the car is
* straight through the intersection entering from direction X will leave to * considered in quadrant 0 until you call inQuadrant(3). After you call
* direction (X + 2) % 4 and pass through quadrants X and (X + 3) % 4. * inQuadrant(2), the car is considered in quadrant 2 until you call
* Boo-yah. * 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() * Your solutions below should call the inQuadrant() and leaveIntersection()
* functions in synchprobs.c to record their progress. * functions in synchprobs.c to record their progress.

View File

@ -1,8 +1,8 @@
/* /*
* 08 Feb 2012 : GWA : Please make any changes necessary to test your code to * NO NOT MODIFY THIS FILE
* the drivers in this file. However, the automated testing suite *will *
* replace this file in its entirety* with driver code intented to stress * All the contents of this file are overwritten during automated
* test your synchronization problem solutions. * testing. Please consider this before changing anything in this file.
*/ */
#include <types.h> #include <types.h>
@ -17,50 +17,39 @@
#define PROBLEMS_MAX_SPINNER 8192 #define PROBLEMS_MAX_SPINNER 8192
/* /*
* 08 Feb 2012 : GWA : Driver code for the whalemating problem. * 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.
*/ */
inline void male_start(void) { inline void male_start(void) {
random_yielder(PROBLEMS_MAX_YIELDER); 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) { inline void male_end(void) {
kprintf("%s ending\n", curthread->t_name); tkprintf("%s ending\n", curthread->t_name);
} }
inline void female_start(void) { inline void female_start(void) {
random_spinner(PROBLEMS_MAX_SPINNER); 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) { inline void female_end(void) {
kprintf("%s ending\n", curthread->t_name); tkprintf("%s ending\n", curthread->t_name);
} }
inline void matchmaker_start(void) { inline void matchmaker_start(void) {
random_yielder(PROBLEMS_MAX_YIELDER); 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) { 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 #define NMATING 10
struct semaphore * whalematingMenuSemaphore; struct semaphore * whalematingMenuSemaphore;
@ -72,8 +61,7 @@ int whalemating(int nargs, char **args) {
int i, j, err = 0; int i, j, err = 0;
char name[32]; char name[32];
whalematingMenuSemaphore = sem_create("Whalemating Driver Semaphore", whalematingMenuSemaphore = sem_create("Whalemating Driver Semaphore", 0);
0);
if (whalematingMenuSemaphore == NULL ) { if (whalematingMenuSemaphore == NULL ) {
panic("whalemating: sem_create failed.\n"); 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. * 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.
*/ */
inline void inQuadrant(int quadrant) { inline void inQuadrant(int quadrant) {
random_spinner(PROBLEMS_MAX_SPINNER); 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() { 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; struct semaphore * stoplightMenuSemaphore;