123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #include <stdio.h>
- #include <stdlib.h>
- #include "test.h"
- #define NUMTHREADS OS_MAX_SIMUL_THREADS
- static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
- static pthread_t threads[NUMTHREADS];
- static unsigned numThreads = 0;
- static void *
- myfunc(void *arg)
- {
- pthread_mutex_lock(&lock);
- numThreads++;
- pthread_mutex_unlock(&lock);
- pte_osThreadSleep(1000);
- return 0;
- }
- int pthread_test_count1()
- {
- int i;
- int maxThreads = sizeof(threads) / sizeof(pthread_t);
- numThreads = 0;
- lock = PTHREAD_MUTEX_INITIALIZER;
-
- for (i = 0; i < maxThreads; i++)
- {
- assert(pthread_create(&threads[i], NULL, myfunc, 0) == 0);
- }
-
- for (i = 0; i < maxThreads; i++)
- {
- assert(pthread_join(threads[i], NULL) == 0);
- }
-
- assert((int) numThreads == maxThreads);
- assert(pthread_mutex_destroy(&lock) == 0);
-
- return 0;
- }
|