diff options
author | rpj <rpj> | 2005-05-06 07:27:10 +0000 |
---|---|---|
committer | rpj <rpj> | 2005-05-06 07:27:10 +0000 |
commit | 7523c7c4d75652f67cd31cb123e1268790394c8b (patch) | |
tree | 0920ebf089ccb971e0878542f85486171a541a8a /tests/tsd1.c | |
parent | cf42850c77554311e62d3780f6a36cbc38e5e002 (diff) |
''
Diffstat (limited to 'tests/tsd1.c')
-rw-r--r-- | tests/tsd1.c | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/tests/tsd1.c b/tests/tsd1.c index 6e21d2a..4d89165 100644 --- a/tests/tsd1.c +++ b/tests/tsd1.c @@ -34,6 +34,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * + * -------------------------------------------------------------------------- + * * Description: * - * @@ -77,10 +79,15 @@ #include <sched.h> #include "test.h" +enum { + NUM_THREADS = 100 +}; + static pthread_key_t key = NULL; -static int accesscount[10]; -static int thread_set[10]; -static int thread_destroyed[10]; +static int accesscount[NUM_THREADS]; +static int thread_set[NUM_THREADS]; +static int thread_destroyed[NUM_THREADS]; +static pthread_barrier_t startBarrier; static void destroy_key(void * arg) @@ -117,10 +124,7 @@ setkey(void * arg) static void * mythread(void * arg) { - while (key == NULL) - { - sched_yield(); - } + (void) pthread_barrier_wait(&startBarrier); setkey(arg); @@ -134,22 +138,24 @@ main() { int i; int fail = 0; - pthread_t thread[10]; + pthread_t thread[NUM_THREADS]; - for (i = 1; i < 5; i++) + assert(pthread_barrier_init(&startBarrier, NULL, NUM_THREADS/2) == 0); + + for (i = 1; i < NUM_THREADS/2; i++) { accesscount[i] = thread_set[i] = thread_destroyed[i] = 0; assert(pthread_create(&thread[i], NULL, mythread, (void *)&accesscount[i]) == 0); } - Sleep(2000); - /* * Here we test that existing threads will get a key created * for them. */ assert(pthread_key_create(&key, destroy_key) == 0); + (void) pthread_barrier_wait(&startBarrier); + /* * Test main thread key. */ @@ -160,16 +166,16 @@ main() * Here we test that new threads will get a key created * for them. */ - for (i = 5; i < 10; i++) + for (i = NUM_THREADS/2; i < NUM_THREADS; i++) { - accesscount[i] = thread_set[i] = thread_destroyed[i] = 0; + accesscount[i] = thread_set[i] = thread_destroyed[i] = 0; assert(pthread_create(&thread[i], NULL, mythread, (void *)&accesscount[i]) == 0); } /* * Wait for all threads to complete. */ - for (i = 1; i < 10; i++) + for (i = 1; i < NUM_THREADS; i++) { int result = 0; @@ -178,7 +184,9 @@ main() assert(pthread_key_delete(key) == 0); - for (i = 1; i < 10; i++) + assert(pthread_barrier_destroy(&startBarrier) == 0); + + for (i = 1; i < NUM_THREADS; i++) { /* * The counter is incremented once when the key is set to |