root/kern/synchprobs/whalemating.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. male
  2. female
  3. matchmaker
  4. whalemating

   1 /*
   2  * Copyright (c) 2001, 2002, 2009
   3  *      The President and Fellows of Harvard College.
   4  *
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  * 1. Redistributions of source code must retain the above copyright
   9  *    notice, this list of conditions and the following disclaimer.
  10  * 2. Redistributions in binary form must reproduce the above copyright
  11  *    notice, this list of conditions and the following disclaimer in the
  12  *    documentation and/or other materials provided with the distribution.
  13  * 3. Neither the name of the University nor the names of its contributors
  14  *    may be used to endorse or promote products derived from this software
  15  *    without specific prior written permission.
  16  *
  17  * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
  18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
  21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27  * SUCH DAMAGE.
  28  */
  29 
  30 /*
  31  * Driver code for whale mating problem
  32  */
  33 #include <types.h>
  34 #include <lib.h>
  35 #include <thread.h>
  36 #include <test.h>
  37 
  38 #define NMATING 10
  39 
  40 static
  41 void
  42 male(void *p, unsigned long which)
  43 {
  44         (void)p;
  45         kprintf("male whale #%ld starting\n", which);
  46 
  47         // Implement this function 
  48 }
  49 
  50 static
  51 void
  52 female(void *p, unsigned long which)
  53 {
  54         (void)p;
  55         kprintf("female whale #%ld starting\n", which);
  56 
  57         // Implement this function 
  58 }
  59 
  60 static
  61 void
  62 matchmaker(void *p, unsigned long which)
  63 {
  64         (void)p;
  65         kprintf("matchmaker whale #%ld starting\n", which);
  66 
  67         // Implement this function 
  68 }
  69 
  70 
  71 // Change this function as necessary
  72 int
  73 whalemating(int nargs, char **args)
  74 {
  75 
  76         int i, j, err=0;
  77         
  78         (void)nargs;
  79         (void)args;
  80 
  81         for (i = 0; i < 3; i++) {
  82                 for (j = 0; j < NMATING; j++) {
  83 #ifdef UW
  84                         switch(i) {
  85                             case 0:
  86                                 err = thread_fork("Male Whale Thread", NULL,
  87                                                   male, NULL, j);
  88                                 break;
  89                             case 1:
  90                                 err = thread_fork("Female Whale Thread", NULL,
  91                                                   female, NULL, j);
  92                                 break;
  93                             case 2:
  94                                 err = thread_fork("Matchmaker Whale Thread", NULL,
  95                                                   matchmaker, NULL, j);
  96                                 break;
  97                         }
  98 #else
  99                         switch(i) {
 100                             case 0:
 101                                 err = thread_fork("Male Whale Thread",
 102                                                   male, NULL, j, NULL);
 103                                 break;
 104                             case 1:
 105                                 err = thread_fork("Female Whale Thread",
 106                                                   female, NULL, j, NULL);
 107                                 break;
 108                             case 2:
 109                                 err = thread_fork("Matchmaker Whale Thread",
 110                                                   matchmaker, NULL, j, NULL);
 111                                 break;
 112                         }
 113 #endif /* UW */
 114                         if (err) {
 115                                 panic("whalemating: thread_fork failed: %s)\n",
 116                                       strerror(err));
 117                         }
 118                 }
 119         }
 120 
 121         return 0;
 122 }

/* [<][>][^][v][top][bottom][index][help] */