5
* --------------------------------------------------------------------------
7
* Pthreads-win32 - POSIX Threads Library for Win32
8
* Copyright(C) 1998 John E. Bossom
9
* Copyright(C) 1999,2005 Pthreads-win32 contributors
11
* Contact Email: rpj@callisto.canberra.edu.au
13
* The current list of contributors is contained
14
* in the file CONTRIBUTORS included with the source
15
* code distribution. The list can also be seen at the
16
* following World Wide Web location:
17
* http://sources.redhat.com/pthreads-win32/contributors.html
19
* This library is free software; you can redistribute it and/or
20
* modify it under the terms of the GNU Lesser General Public
21
* License as published by the Free Software Foundation; either
22
* version 2 of the License, or (at your option) any later version.
24
* This library is distributed in the hope that it will be useful,
25
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27
* Lesser General Public License for more details.
29
* You should have received a copy of the GNU Lesser General Public
30
* License along with this library in the file COPYING.LIB;
31
* if not, write to the Free Software Foundation, Inc.,
32
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
34
* --------------------------------------------------------------------------
37
* - Test basic function of a CV
39
* Test Method (Validation or Falsification):
42
* Requirements Tested:
52
* - The primary thread takes the lock before creating any threads.
53
* The secondary thread blocks on the lock allowing the primary
54
* thread to enter the cv wait state which releases the lock.
55
* The secondary thread then takes the lock and signals the waiting
65
* - File name, Line number, and failed expression on failure.
66
* - No output on success.
72
* - pthread_cond_timedwait returns 0.
73
* - Process returns zero exit status.
76
* - pthread_cond_timedwait returns ETIMEDOUT.
77
* - Process returns non-zero exit status.
81
#include <sys/timeb.h>
83
static pthread_cond_t cv;
84
static pthread_mutex_t mutex;
85
static int shared = 0;
88
NUMTHREADS = 2 /* Including the primary thread. */
96
assert(pthread_mutex_lock(&mutex) == 0);
98
assert(pthread_mutex_unlock(&mutex) == 0);
100
if ((result = pthread_cond_signal(&cv)) != 0)
102
printf("Error = %s\n", error_string[result]);
113
pthread_t t[NUMTHREADS];
114
struct timespec abstime = { 0, 0 };
115
struct _timeb currSysTime;
116
const DWORD NANOSEC_PER_MILLISEC = 1000000;
118
assert((t[0] = pthread_self()).p != NULL);
120
assert(pthread_cond_init(&cv, NULL) == 0);
122
assert(pthread_mutex_init(&mutex, NULL) == 0);
124
assert(pthread_mutex_lock(&mutex) == 0);
126
/* get current system time */
127
_ftime(&currSysTime);
129
abstime.tv_sec = currSysTime.time;
130
abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
132
assert(pthread_create(&t[1], NULL, mythread, (void *) 1) == 0);
136
while (! (shared > 0))
137
assert(pthread_cond_timedwait(&cv, &mutex, &abstime) == 0);
141
assert(pthread_mutex_unlock(&mutex) == 0);
143
assert(pthread_join(t[1], NULL) == 0);
145
assert(pthread_cond_destroy(&cv) == 0);