123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #include "test.h"
- static pthread_once_t once = PTHREAD_ONCE_INIT;
- static int washere = 0;
- static void
- myfunc(void)
- {
- washere++;
- }
- static void *
- mythread(void * arg)
- {
- assert(pthread_once(&once, myfunc) == 0);
- return 0;
- }
- int pthread_test_once1()
- {
- pthread_t t1, t2;
- pthread_once_t onceinit = PTHREAD_ONCE_INIT;
- washere = 0;
- once = onceinit;
- assert(pthread_create(&t1, NULL, mythread, NULL) == 0);
- assert(pthread_create(&t2, NULL, mythread, NULL) == 0);
- pte_osThreadSleep(2000);
- assert(washere == 1);
- assert(pthread_join(t1,NULL) == 0);
- assert(pthread_join(t2,NULL) == 0);
- return 0;
- }
|