123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #include "test.h"
- static sem_t s;
- static int semStatus;
- static void *
- thr (void * arg)
- {
- struct timespec abstime =
- {
- 0, 0
- };
- struct _timeb currSysTime;
- const long long NANOSEC_PER_MILLISEC = 1000000;
- _ftime(&currSysTime);
- abstime.tv_sec = currSysTime.time;
- abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
- abstime.tv_sec += 5;
- assert(sem_timedwait(&s, &abstime) == -1);
- assert(errno == ETIMEDOUT);
- semStatus = 1;
-
- return NULL;
- }
- int pthread_test_semaphore6(void)
- {
- int value = 0;
- pthread_t handle;
- assert(sem_init(&s, PTHREAD_PROCESS_PRIVATE, 0) == 0);
- assert(sem_getvalue(&s, &value) == 0);
- assert(value == 0);
- semStatus = 0;
- assert(pthread_create(&handle, NULL, thr, NULL) == 0);
- pte_osThreadSleep(3000);
-
- assert(semStatus == 0);
- assert(pthread_join(handle, NULL) == 0);
- assert(sem_destroy(&s) == 0);
- return 0;
- }
|