change synchprobs codes for reliable test.
This commit is contained in:
parent
59d447acf6
commit
5e3334057a
@ -117,16 +117,16 @@ void kmain(char *bootstring);
|
|||||||
* Synchronization driver primitives.
|
* Synchronization driver primitives.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void male_start(void);
|
void male_start(uint32_t);
|
||||||
void male_end(void);
|
void male_end(uint32_t);
|
||||||
void female_start(void);
|
void female_start(uint32_t);
|
||||||
void female_end(void);
|
void female_end(uint32_t);
|
||||||
void matchmaker_start(void);
|
void matchmaker_start(uint32_t);
|
||||||
void matchmaker_end(void);
|
void matchmaker_end(uint32_t);
|
||||||
int whalemating(int, char **);
|
int whalemating(int, char **);
|
||||||
|
|
||||||
void inQuadrant(int);
|
void inQuadrant(int, uint32_t);
|
||||||
void leaveIntersection(void);
|
void leaveIntersection(uint32_t);
|
||||||
int stoplight(int, char **);
|
int stoplight(int, char **);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -139,17 +139,17 @@ int stoplight(int, char **);
|
|||||||
|
|
||||||
void whalemating_init(void);
|
void whalemating_init(void);
|
||||||
void whalemating_cleanup(void);
|
void whalemating_cleanup(void);
|
||||||
void male(void);
|
void male(uint32_t);
|
||||||
void female(void);
|
void female(uint32_t);
|
||||||
void matchmaker(void);
|
void matchmaker(uint32_t);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* stoplight.c.
|
* stoplight.c.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void gostraight(uint32_t);
|
void gostraight(uint32_t, uint32_t);
|
||||||
void turnleft(uint32_t);
|
void turnleft(uint32_t, uint32_t);
|
||||||
void turnright(uint32_t);
|
void turnright(uint32_t, uint32_t);
|
||||||
void stoplight_init(void);
|
void stoplight_init(void);
|
||||||
void stoplight_cleanup(void);
|
void stoplight_cleanup(void);
|
||||||
|
|
||||||
|
@ -87,27 +87,30 @@ void stoplight_cleanup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
turnright(uint32_t direction)
|
turnright(uint32_t direction, uint32_t index)
|
||||||
{
|
{
|
||||||
(void)direction;
|
(void)direction;
|
||||||
|
(void)index;
|
||||||
/*
|
/*
|
||||||
* Implement this function.
|
* Implement this function.
|
||||||
*/
|
*/
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
gostraight(uint32_t direction)
|
gostraight(uint32_t direction, uint32_t index)
|
||||||
{
|
{
|
||||||
(void)direction;
|
(void)direction;
|
||||||
|
(void)index;
|
||||||
/*
|
/*
|
||||||
* Implement this function.
|
* Implement this function.
|
||||||
*/
|
*/
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
turnleft(uint32_t direction)
|
turnleft(uint32_t direction, uint32_t index)
|
||||||
{
|
{
|
||||||
(void)direction;
|
(void)direction;
|
||||||
|
(void)index;
|
||||||
/*
|
/*
|
||||||
* Implement this function.
|
* Implement this function.
|
||||||
*/
|
*/
|
||||||
|
@ -58,8 +58,9 @@ whalemating_cleanup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
male()
|
male(uint32_t index)
|
||||||
{
|
{
|
||||||
|
(void)index;
|
||||||
/*
|
/*
|
||||||
* Implement this function by calling male_start and male_end when
|
* Implement this function by calling male_start and male_end when
|
||||||
* appropriate.
|
* appropriate.
|
||||||
@ -68,8 +69,9 @@ male()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
female()
|
female(uint32_t index)
|
||||||
{
|
{
|
||||||
|
(void)index;
|
||||||
/*
|
/*
|
||||||
* Implement this function by calling female_start and female_end when
|
* Implement this function by calling female_start and female_end when
|
||||||
* appropriate.
|
* appropriate.
|
||||||
@ -78,8 +80,9 @@ female()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
matchmaker()
|
matchmaker(uint32_t index)
|
||||||
{
|
{
|
||||||
|
(void)index;
|
||||||
/*
|
/*
|
||||||
* Implement this function by calling matchmaker_start and matchmaker_end
|
* Implement this function by calling matchmaker_start and matchmaker_end
|
||||||
* when appropriate.
|
* when appropriate.
|
||||||
|
@ -56,9 +56,8 @@ inititems(uint32_t count)
|
|||||||
|
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
male_wrapper(void * unused1, unsigned long unused2) {
|
male_wrapper(void * unused1, unsigned long index) {
|
||||||
(void)unused1;
|
(void)unused1;
|
||||||
(void)unused2;
|
|
||||||
|
|
||||||
random_yielder(4);
|
random_yielder(4);
|
||||||
lock_acquire(startlock);
|
lock_acquire(startlock);
|
||||||
@ -69,19 +68,21 @@ male_wrapper(void * unused1, unsigned long unused2) {
|
|||||||
cv_wait(startcv, startlock);
|
cv_wait(startcv, startlock);
|
||||||
}
|
}
|
||||||
lock_release(startlock);
|
lock_release(startlock);
|
||||||
male();
|
male((uint32_t)index);
|
||||||
V(endsem);
|
V(endsem);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
male_start(void) {
|
male_start(uint32_t index) {
|
||||||
|
(void)index;
|
||||||
random_yielder(PROBLEMS_MAX_YIELDER);
|
random_yielder(PROBLEMS_MAX_YIELDER);
|
||||||
random_spinner(PROBLEMS_MAX_SPINNER);
|
random_spinner(PROBLEMS_MAX_SPINNER);
|
||||||
tkprintf("%s starting\n", curthread->t_name);
|
tkprintf("%s starting\n", curthread->t_name);
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
male_end(void) {
|
male_end(uint32_t index) {
|
||||||
|
(void)index;
|
||||||
random_yielder(PROBLEMS_MAX_YIELDER);
|
random_yielder(PROBLEMS_MAX_YIELDER);
|
||||||
random_spinner(PROBLEMS_MAX_SPINNER);
|
random_spinner(PROBLEMS_MAX_SPINNER);
|
||||||
tkprintf("%s ending\n", curthread->t_name);
|
tkprintf("%s ending\n", curthread->t_name);
|
||||||
@ -89,9 +90,8 @@ male_end(void) {
|
|||||||
|
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
female_wrapper(void * unused1, unsigned long unused2) {
|
female_wrapper(void * unused1, unsigned long index) {
|
||||||
(void)unused1;
|
(void)unused1;
|
||||||
(void)unused2;
|
|
||||||
|
|
||||||
random_yielder(4);
|
random_yielder(4);
|
||||||
lock_acquire(startlock);
|
lock_acquire(startlock);
|
||||||
@ -102,19 +102,21 @@ female_wrapper(void * unused1, unsigned long unused2) {
|
|||||||
cv_wait(startcv, startlock);
|
cv_wait(startcv, startlock);
|
||||||
}
|
}
|
||||||
lock_release(startlock);
|
lock_release(startlock);
|
||||||
female();
|
female((uint32_t)index);
|
||||||
V(endsem);
|
V(endsem);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
female_start(void) {
|
female_start(uint32_t index) {
|
||||||
|
(void) index;
|
||||||
random_yielder(PROBLEMS_MAX_YIELDER);
|
random_yielder(PROBLEMS_MAX_YIELDER);
|
||||||
random_spinner(PROBLEMS_MAX_SPINNER);
|
random_spinner(PROBLEMS_MAX_SPINNER);
|
||||||
tkprintf("%s starting\n", curthread->t_name);
|
tkprintf("%s starting\n", curthread->t_name);
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
female_end(void) {
|
female_end(uint32_t index) {
|
||||||
|
(void) index;
|
||||||
random_yielder(PROBLEMS_MAX_YIELDER);
|
random_yielder(PROBLEMS_MAX_YIELDER);
|
||||||
random_spinner(PROBLEMS_MAX_SPINNER);
|
random_spinner(PROBLEMS_MAX_SPINNER);
|
||||||
tkprintf("%s ending\n", curthread->t_name);
|
tkprintf("%s ending\n", curthread->t_name);
|
||||||
@ -122,9 +124,8 @@ female_end(void) {
|
|||||||
|
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
matchmaker_wrapper(void * unused1, unsigned long unused2) {
|
matchmaker_wrapper(void * unused1, unsigned long index) {
|
||||||
(void)unused1;
|
(void)unused1;
|
||||||
(void)unused2;
|
|
||||||
|
|
||||||
random_yielder(4);
|
random_yielder(4);
|
||||||
lock_acquire(startlock);
|
lock_acquire(startlock);
|
||||||
@ -135,19 +136,21 @@ matchmaker_wrapper(void * unused1, unsigned long unused2) {
|
|||||||
cv_wait(startcv, startlock);
|
cv_wait(startcv, startlock);
|
||||||
}
|
}
|
||||||
lock_release(startlock);
|
lock_release(startlock);
|
||||||
matchmaker();
|
matchmaker((uint32_t)index);
|
||||||
V(endsem);
|
V(endsem);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
matchmaker_start(void) {
|
matchmaker_start(uint32_t index) {
|
||||||
|
(void)index;
|
||||||
random_yielder(PROBLEMS_MAX_YIELDER);
|
random_yielder(PROBLEMS_MAX_YIELDER);
|
||||||
random_spinner(PROBLEMS_MAX_SPINNER);
|
random_spinner(PROBLEMS_MAX_SPINNER);
|
||||||
tkprintf("%s starting\n", curthread->t_name);
|
tkprintf("%s starting\n", curthread->t_name);
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
matchmaker_end(void) {
|
matchmaker_end(uint32_t index) {
|
||||||
|
(void)index;
|
||||||
random_yielder(PROBLEMS_MAX_YIELDER);
|
random_yielder(PROBLEMS_MAX_YIELDER);
|
||||||
random_spinner(PROBLEMS_MAX_SPINNER);
|
random_spinner(PROBLEMS_MAX_SPINNER);
|
||||||
tkprintf("%s ending\n", curthread->t_name);
|
tkprintf("%s ending\n", curthread->t_name);
|
||||||
@ -171,15 +174,15 @@ whalemating(int nargs, char **args) {
|
|||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
snprintf(name, sizeof(name), "Male Whale Thread %d", (i * 3) + j);
|
snprintf(name, sizeof(name), "Male Whale Thread %d", (i * 3) + j);
|
||||||
err = thread_fork(name, NULL, male_wrapper, NULL, 0);
|
err = thread_fork(name, NULL, male_wrapper, NULL, j);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
snprintf(name, sizeof(name), "Female Whale Thread %d", (i * 3) + j);
|
snprintf(name, sizeof(name), "Female Whale Thread %d", (i * 3) + j);
|
||||||
err = thread_fork(name, NULL, female_wrapper, NULL, 0);
|
err = thread_fork(name, NULL, female_wrapper, NULL, j);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
snprintf(name, sizeof(name), "Matchmaker Whale Thread %d", (i * 3) + j);
|
snprintf(name, sizeof(name), "Matchmaker Whale Thread %d", (i * 3) + j);
|
||||||
err = thread_fork(name, NULL, matchmaker_wrapper, NULL, 0);
|
err = thread_fork(name, NULL, matchmaker_wrapper, NULL, j);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -205,10 +208,8 @@ whalemating(int nargs, char **args) {
|
|||||||
|
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
turnright_wrapper(void *unused, unsigned long direction)
|
turnright_wrapper(void *index, unsigned long direction)
|
||||||
{
|
{
|
||||||
(void)unused;
|
|
||||||
|
|
||||||
random_yielder(4);
|
random_yielder(4);
|
||||||
lock_acquire(startlock);
|
lock_acquire(startlock);
|
||||||
startcount--;
|
startcount--;
|
||||||
@ -218,17 +219,15 @@ turnright_wrapper(void *unused, unsigned long direction)
|
|||||||
cv_wait(startcv, startlock);
|
cv_wait(startcv, startlock);
|
||||||
}
|
}
|
||||||
lock_release(startlock);
|
lock_release(startlock);
|
||||||
turnright((uint32_t)direction);
|
turnright((uint32_t)direction, (uint32_t)index);
|
||||||
V(endsem);
|
V(endsem);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
gostraight_wrapper(void *unused, unsigned long direction)
|
gostraight_wrapper(void *index, unsigned long direction)
|
||||||
{
|
{
|
||||||
(void)unused;
|
|
||||||
|
|
||||||
random_yielder(4);
|
random_yielder(4);
|
||||||
lock_acquire(startlock);
|
lock_acquire(startlock);
|
||||||
startcount--;
|
startcount--;
|
||||||
@ -238,17 +237,15 @@ gostraight_wrapper(void *unused, unsigned long direction)
|
|||||||
cv_wait(startcv, startlock);
|
cv_wait(startcv, startlock);
|
||||||
}
|
}
|
||||||
lock_release(startlock);
|
lock_release(startlock);
|
||||||
gostraight((uint32_t)direction);
|
gostraight((uint32_t)direction, (uint32_t)index);
|
||||||
V(endsem);
|
V(endsem);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
turnleft_wrapper(void *unused, unsigned long direction)
|
turnleft_wrapper(void *index, unsigned long direction)
|
||||||
{
|
{
|
||||||
(void)unused;
|
|
||||||
|
|
||||||
random_yielder(4);
|
random_yielder(4);
|
||||||
lock_acquire(startlock);
|
lock_acquire(startlock);
|
||||||
startcount--;
|
startcount--;
|
||||||
@ -258,21 +255,25 @@ turnleft_wrapper(void *unused, unsigned long direction)
|
|||||||
cv_wait(startcv, startlock);
|
cv_wait(startcv, startlock);
|
||||||
}
|
}
|
||||||
lock_release(startlock);
|
lock_release(startlock);
|
||||||
turnleft((uint32_t)direction);
|
turnleft((uint32_t)direction, (uint32_t)index);
|
||||||
V(endsem);
|
V(endsem);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
inQuadrant(int quadrant) {
|
inQuadrant(int quadrant, uint32_t index) {
|
||||||
|
(void)index;
|
||||||
|
|
||||||
random_yielder(PROBLEMS_MAX_YIELDER);
|
random_yielder(PROBLEMS_MAX_YIELDER);
|
||||||
random_spinner(PROBLEMS_MAX_SPINNER);
|
random_spinner(PROBLEMS_MAX_SPINNER);
|
||||||
tkprintf("%s in quadrant %d\n", curthread->t_name, quadrant);
|
tkprintf("%s in quadrant %d\n", curthread->t_name, quadrant);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
leaveIntersection() {
|
leaveIntersection(uint32_t index) {
|
||||||
|
(void)index;
|
||||||
|
|
||||||
random_yielder(PROBLEMS_MAX_YIELDER);
|
random_yielder(PROBLEMS_MAX_YIELDER);
|
||||||
random_spinner(PROBLEMS_MAX_SPINNER);
|
random_spinner(PROBLEMS_MAX_SPINNER);
|
||||||
tkprintf("%s left the intersection\n", curthread->t_name);
|
tkprintf("%s left the intersection\n", curthread->t_name);
|
||||||
@ -300,13 +301,13 @@ int stoplight(int nargs, char **args) {
|
|||||||
|
|
||||||
switch (turn) {
|
switch (turn) {
|
||||||
case 0:
|
case 0:
|
||||||
err = thread_fork(name, NULL, gostraight_wrapper, NULL, direction);
|
err = thread_fork(name, NULL, gostraight_wrapper, (void *)i, direction);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
err = thread_fork(name, NULL, turnleft_wrapper, NULL, direction);
|
err = thread_fork(name, NULL, turnleft_wrapper, (void *)i, direction);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
err = thread_fork(name, NULL, turnright_wrapper, NULL, direction);
|
err = thread_fork(name, NULL, turnright_wrapper, (void *)i, direction);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (err) {
|
if (err) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user