00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
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
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
00068 }
00069
00070
00071
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
00114 if (err) {
00115 panic("whalemating: thread_fork failed: %s)\n",
00116 strerror(err));
00117 }
00118 }
00119 }
00120
00121 return 0;
00122 }