Changeset cb01e1e in mainline for kernel/test/synch/semaphore1.c
- Timestamp:
- 2009-04-04T00:26:27Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a85aebd
- Parents:
- 171f9a1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/synch/semaphore1.c
r171f9a1 rcb01e1e 36 36 #include <synch/semaphore.h> 37 37 38 #define AT_ONCE 39 #define PRODUCERS 40 #define CONSUMERS 38 #define AT_ONCE 3 39 #define PRODUCERS 50 40 #define CONSUMERS 50 41 41 42 42 static semaphore_t sem; … … 48 48 static void producer(void *arg) 49 49 { 50 thread_detach(THREAD); 51 50 thread_detach(THREAD); 51 52 52 waitq_sleep(&can_start); 53 53 54 54 semaphore_down(&sem); 55 55 atomic_inc(&items_produced); … … 60 60 static void consumer(void *arg) 61 61 { 62 thread_detach(THREAD); 62 thread_detach(THREAD); 63 63 64 64 waitq_sleep(&can_start); … … 70 70 } 71 71 72 char * test_semaphore1(bool quiet)72 char *test_semaphore1(void) 73 73 { 74 74 int i, j, k; … … 77 77 waitq_initialize(&can_start); 78 78 semaphore_initialize(&sem, AT_ONCE); 79 79 80 80 for (i = 1; i <= 3; i++) { 81 81 thread_t *thrd; 82 82 83 83 atomic_set(&items_produced, 0); 84 84 atomic_set(&items_consumed, 0); … … 87 87 producers = (4 - i) * PRODUCERS; 88 88 89 printf("Creating %d consumers and %d producers...", consumers, producers);90 89 TPRINTF("Creating %d consumers and %d producers...", consumers, producers); 90 91 91 for (j = 0; j < (CONSUMERS + PRODUCERS) / 2; j++) { 92 92 for (k = 0; k < i; k++) { … … 95 95 thread_ready(thrd); 96 96 else 97 printf("could not create consumer %d\n", i);97 TPRINTF("could not create consumer %d\n", i); 98 98 } 99 99 for (k = 0; k < (4 - i); k++) { … … 102 102 thread_ready(thrd); 103 103 else 104 printf("could not create producer %d\n", i);104 TPRINTF("could not create producer %d\n", i); 105 105 } 106 106 } 107 108 printf("ok\n");109 107 108 TPRINTF("ok\n"); 109 110 110 thread_sleep(1); 111 111 waitq_wakeup(&can_start, WAKEUP_ALL); 112 112 113 113 while ((items_consumed.count != consumers) || (items_produced.count != producers)) { 114 printf("%d consumers remaining, %d producers remaining\n", consumers - items_consumed.count, producers - items_produced.count);114 TPRINTF("%d consumers remaining, %d producers remaining\n", consumers - items_consumed.count, producers - items_produced.count); 115 115 thread_sleep(1); 116 116 }
Note:
See TracChangeset
for help on using the changeset viewer.