os161-1.99
 All Data Structures
whalemating.c
00001 /*
00002  * Copyright (c) 2001, 2002, 2009
00003  *      The President and Fellows of Harvard College.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 
00030 /*
00031  * Driver code for whale mating problem
00032  */
00033 #include <types.h>
00034 #include <lib.h>
00035 #include <thread.h>
00036 #include <test.h>
00037 
00038 #define NMATING 10
00039 
00040 static
00041 void
00042 male(void *p, unsigned long which)
00043 {
00044         (void)p;
00045         kprintf("male whale #%ld starting\n", which);
00046 
00047         // Implement this function 
00048 }
00049 
00050 static
00051 void
00052 female(void *p, unsigned long which)
00053 {
00054         (void)p;
00055         kprintf("female whale #%ld starting\n", which);
00056 
00057         // Implement this function 
00058 }
00059 
00060 static
00061 void
00062 matchmaker(void *p, unsigned long which)
00063 {
00064         (void)p;
00065         kprintf("matchmaker whale #%ld starting\n", which);
00066 
00067         // Implement this function 
00068 }
00069 
00070 
00071 // Change this function as necessary
00072 int
00073 whalemating(int nargs, char **args)
00074 {
00075 
00076         int i, j, err=0;
00077         
00078         (void)nargs;
00079         (void)args;
00080 
00081         for (i = 0; i < 3; i++) {
00082                 for (j = 0; j < NMATING; j++) {
00083 #ifdef UW
00084                         switch(i) {
00085                             case 0:
00086                                 err = thread_fork("Male Whale Thread", NULL,
00087                                                   male, NULL, j);
00088                                 break;
00089                             case 1:
00090                                 err = thread_fork("Female Whale Thread", NULL,
00091                                                   female, NULL, j);
00092                                 break;
00093                             case 2:
00094                                 err = thread_fork("Matchmaker Whale Thread", NULL,
00095                                                   matchmaker, NULL, j);
00096                                 break;
00097                         }
00098 #else
00099                         switch(i) {
00100                             case 0:
00101                                 err = thread_fork("Male Whale Thread",
00102                                                   male, NULL, j, NULL);
00103                                 break;
00104                             case 1:
00105                                 err = thread_fork("Female Whale Thread",
00106                                                   female, NULL, j, NULL);
00107                                 break;
00108                             case 2:
00109                                 err = thread_fork("Matchmaker Whale Thread",
00110                                                   matchmaker, NULL, j, NULL);
00111                                 break;
00112                         }
00113 #endif /* UW */
00114                         if (err) {
00115                                 panic("whalemating: thread_fork failed: %s)\n",
00116                                       strerror(err));
00117                         }
00118                 }
00119         }
00120 
00121         return 0;
00122 }
 All Data Structures