45,10 → 45,6 |
static atomic_t items_produced; |
static atomic_t items_consumed; |
|
static void consumer(void *arg); |
static void producer(void *arg); |
static void failed(void); |
|
static void producer(void *arg) |
{ |
thread_detach(THREAD); |
73,23 → 69,14 |
semaphore_up(&sem); |
} |
|
static void failed(void) |
char * test_semaphore1(void) |
{ |
printf("Test failed prematurely.\n"); |
thread_exit(); |
} |
|
void test_semaphore1(void) |
{ |
int i, j, k; |
int consumers, producers; |
|
printf("Semaphore test #1\n"); |
|
waitq_initialize(&can_start); |
semaphore_initialize(&sem, AT_ONCE); |
|
|
for (i=1; i<=3; i++) { |
thread_t *thrd; |
|
107,7 → 94,7 |
if (thrd) |
thread_ready(thrd); |
else |
failed(); |
printf("could not create consumer %d\n", i); |
} |
for (k=0; k<(4-i); k++) { |
thrd = thread_create(producer, NULL, TASK, 0, "producer"); |
114,7 → 101,7 |
if (thrd) |
thread_ready(thrd); |
else |
failed(); |
printf("could not create producer %d\n", i); |
} |
} |
|
123,10 → 110,11 |
thread_sleep(1); |
waitq_wakeup(&can_start, WAKEUP_ALL); |
|
while (items_consumed.count != consumers || items_produced.count != producers) { |
while ((items_consumed.count != consumers) || (items_produced.count != producers)) { |
printf("%d consumers remaining, %d producers remaining\n", consumers - items_consumed.count, producers - items_produced.count); |
thread_sleep(1); |
} |
} |
printf("Test passed.\n"); |
|
return NULL; |
} |