Synchronization problem stubs and drivers.
This commit is contained in:
133
kern/synchprobs/stoplight.c
Normal file
133
kern/synchprobs/stoplight.c
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2002, 2009
|
||||
* The President and Fellows of Harvard College.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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)
|
||||
*
|
||||
* | 0 |
|
||||
* -- --
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <types.h>
|
||||
#include <lib.h>
|
||||
#include <thread.h>
|
||||
#include <test.h>
|
||||
#include <synch.h>
|
||||
#include <synchprobs.h>
|
||||
|
||||
/*
|
||||
* Called by the driver during initialization.
|
||||
*/
|
||||
|
||||
void
|
||||
stoplight_init() {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Called by the driver during teardown.
|
||||
*/
|
||||
|
||||
void stoplight_cleanup() {
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
gostraight(void *p, unsigned long direction)
|
||||
{
|
||||
struct semaphore * stoplightMenuSemaphore = (struct semaphore *)p;
|
||||
(void)direction;
|
||||
|
||||
/*
|
||||
* Implement this function.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code allows the test to return to the menu cleanly.
|
||||
*/
|
||||
V(stoplightMenuSemaphore);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
turnleft(void *p, unsigned long direction)
|
||||
{
|
||||
struct semaphore * stoplightMenuSemaphore = (struct semaphore *)p;
|
||||
(void)direction;
|
||||
|
||||
/*
|
||||
* Implement this function.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code allows the test to return to the menu cleanly.
|
||||
*/
|
||||
V(stoplightMenuSemaphore);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
turnright(void *p, unsigned long direction)
|
||||
{
|
||||
struct semaphore * stoplightMenuSemaphore = (struct semaphore *)p;
|
||||
(void)direction;
|
||||
|
||||
/*
|
||||
* Implement this function.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code allows the test to return to the menu cleanly.
|
||||
*/
|
||||
V(stoplightMenuSemaphore);
|
||||
return;
|
||||
}
|
116
kern/synchprobs/whalemating.c
Normal file
116
kern/synchprobs/whalemating.c
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2002, 2009
|
||||
* The President and Fellows of Harvard College.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 whalemating problem below.
|
||||
*/
|
||||
|
||||
#include <types.h>
|
||||
#include <lib.h>
|
||||
#include <thread.h>
|
||||
#include <test.h>
|
||||
#include <synch.h>
|
||||
#include <synchprobs.h>
|
||||
|
||||
/*
|
||||
* Called by the driver during initialization.
|
||||
*/
|
||||
|
||||
void whalemating_init() {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Called by the driver during teardown.
|
||||
*/
|
||||
|
||||
void
|
||||
whalemating_cleanup() {
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
male(void *p, unsigned long which)
|
||||
{
|
||||
struct semaphore * whalematingMenuSemaphore = (struct semaphore *)p;
|
||||
(void)which;
|
||||
|
||||
male_start();
|
||||
/*
|
||||
* Implement this function.
|
||||
*/
|
||||
male_end();
|
||||
|
||||
/*
|
||||
* This code allows the test to return to the menu cleanly.
|
||||
*/
|
||||
V(whalematingMenuSemaphore);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
female(void *p, unsigned long which)
|
||||
{
|
||||
struct semaphore * whalematingMenuSemaphore = (struct semaphore *)p;
|
||||
(void)which;
|
||||
|
||||
female_start();
|
||||
/*
|
||||
* Implement this function.
|
||||
*/
|
||||
female_end();
|
||||
|
||||
/*
|
||||
* This code allows the test to return to the menu cleanly.
|
||||
*/
|
||||
V(whalematingMenuSemaphore);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
matchmaker(void *p, unsigned long which)
|
||||
{
|
||||
struct semaphore * whalematingMenuSemaphore = (struct semaphore *)p;
|
||||
(void)which;
|
||||
|
||||
matchmaker_start();
|
||||
/*
|
||||
* Implement this function.
|
||||
*/
|
||||
matchmaker_end();
|
||||
|
||||
/*
|
||||
* This code allows the test to return to the menu cleanly.
|
||||
*/
|
||||
V(whalematingMenuSemaphore);
|
||||
return;
|
||||
}
|
Reference in New Issue
Block a user