2 ** Copyright 2003, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
8 #include <sys/syscalls.h>
10 int sleep_test(int arg
)
12 printf("should display 'booyah!' 10 times, one second apart\n");
13 for(int i
= 0; i
< 10; i
++) {
15 write(0, "booyah!", strlen("booyah!"));
21 static int test_thread(void *args
)
27 sprintf(buf
, "%c", 'a' + i
);
33 static int test_thread_self_terminate(void *args
)
37 bigtime_t start_time
= _kern_system_time();
40 if(_kern_system_time() - start_time
>= 10000000) {
41 sprintf(buf
, "thread %c terminating...\n", 'a' + i
);
42 write(0, buf
, strlen(buf
));
45 sprintf(buf
, "%c", 'a' + i
);
52 static int dummy_thread(void *args
)
57 static int cpu_eater_thread(void *args
)
63 static int fpu_cruncher_thread(void *args
)
65 double y
= *(double *)args
;
71 if(y
!= *(double *)args
)
72 printf("error: y %f\n", y
);
77 int thread_spawn_test(int arg
)
80 int (*thread_func
)(void *) = NULL
;
84 printf("creating 10 threads, runs forever...\n");
85 thread_func
= &test_thread
;
87 printf("creating 10 threads, then killing them after 10 seconds\n");
88 thread_func
= &test_thread
;
90 printf("creating 10 threads, self terminating after 10 seconds\n");
91 thread_func
= &test_thread_self_terminate
;
95 thread_id tids
[num_threads
];
96 for(i
=0; i
<num_threads
; i
++) {
97 tids
[i
] = _kern_thread_create_thread("foo", thread_func
, (void *)i
);
98 _kern_thread_resume_thread(tids
[i
]);
104 } else if(arg
== 1) {
106 for(i
=0; i
<num_threads
; i
++) {
107 printf("killing thread %d...\n", tids
[i
]);
108 _kern_thread_kill_thread(tids
[i
]);
110 } else if(arg
== 2) {
111 _kern_thread_wait_on_thread(tids
[0], NULL
);