Changeset deada67 in mainline for kernel/test/synch/rwlock3.c
- Timestamp:
- 2006-12-19T17:54:50Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 730376d
- Parents:
- 6536a4a9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/synch/rwlock3.c
r6536a4a9 rdeada67 35 35 #include <synch/rwlock.h> 36 36 37 #define READERS 50 38 #define WRITERS 50 37 #define THREADS 4 39 38 39 static atomic_t thread_count; 40 40 static rwlock_t rwlock; 41 static bool sh_quiet; 41 42 42 43 static void reader(void *arg) 43 44 { 44 45 thread_detach(THREAD); 45 46 printf("cpu%d, tid %d: trying to lock rwlock for reading....\n", CPU->id, THREAD->tid); 46 47 if (!sh_quiet) 48 printf("cpu%d, tid %d: trying to lock rwlock for reading....\n", CPU->id, THREAD->tid); 49 47 50 rwlock_read_lock(&rwlock); 48 rwlock_read_unlock(&rwlock); 49 printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid); 50 51 printf("cpu%d, tid %d: trying to lock rwlock for writing....\n", CPU->id, THREAD->tid); 51 rwlock_read_unlock(&rwlock); 52 53 if (!sh_quiet) { 54 printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid); 55 printf("cpu%d, tid %d: trying to lock rwlock for writing....\n", CPU->id, THREAD->tid); 56 } 52 57 53 58 rwlock_write_lock(&rwlock); 54 59 rwlock_write_unlock(&rwlock); 55 printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid); 60 61 if (!sh_quiet) 62 printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid); 63 64 atomic_dec(&thread_count); 56 65 } 57 66 … … 60 69 int i; 61 70 thread_t *thrd; 71 sh_quiet = quiet; 72 73 atomic_set(&thread_count, THREADS); 62 74 63 75 rwlock_initialize(&rwlock); 64 76 rwlock_write_lock(&rwlock); 65 77 66 for (i = 0; i < 4; i++) {78 for (i = 0; i < THREADS; i++) { 67 79 thrd = thread_create(reader, NULL, TASK, 0, "reader", false); 68 80 if (thrd) 69 81 thread_ready(thrd); 70 else 82 else if (!quiet) 71 83 printf("Could not create reader %d\n", i); 72 84 } 73 85 74 86 thread_sleep(1); 87 rwlock_write_unlock(&rwlock); 75 88 76 rwlock_write_unlock(&rwlock); 89 while (atomic_get(&thread_count) > 0) { 90 if (!quiet) 91 printf("Threads left: %d\n", atomic_get(&thread_count)); 92 thread_sleep(1); 93 } 77 94 78 95 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.