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 timeout of multiple waits on a CV with some signaled.
39
* Test Method (Validation or Falsification):
42
* Requirements Tested:
52
* - Because some CVs are never signaled, we expect their waits to time out.
53
* Some are signaled, the rest time out. Pthread_cond_destroy() will fail
54
* unless all are accounted for, either signaled or timedout.
63
* - File name, Line number, and failed expression on failure.
64
* - No output on success.
70
* - pthread_cond_timedwait returns ETIMEDOUT.
71
* - Process returns zero exit status.
74
* - pthread_cond_timedwait does not return ETIMEDOUT.
75
* - Process returns non-zero exit status.
78
#define _WIN32_WINNT 0x400
81
#include <sys/timeb.h>
83
static pthread_cond_t cv;
84
static pthread_cond_t cv1;
85
static pthread_mutex_t mutex;
86
static pthread_mutex_t mutex1;
87
static struct timespec abstime = { 0, 0 };
88
static int timedout = 0;
89
static int signaled = 0;
90
static int awoken = 0;
91
static int waiting = 0;
102
assert(pthread_mutex_lock(&mutex1) == 0);
104
assert(pthread_mutex_unlock(&mutex1) == 0);
105
assert(pthread_cond_signal(&cv1) == 0);
107
assert(pthread_mutex_lock(&mutex) == 0);
108
result = pthread_cond_timedwait(&cv, &mutex, &abstime);
109
if (result == ETIMEDOUT)
117
assert(pthread_mutex_unlock(&mutex) == 0);
122
#include "../implement.h"
128
pthread_t t[NUMTHREADS + 1];
130
struct _timeb currSysTime;
131
const DWORD NANOSEC_PER_MILLISEC = 1000000;
133
assert(pthread_cond_init(&cv, NULL) == 0);
134
assert(pthread_cond_init(&cv1, NULL) == 0);
136
assert(pthread_mutex_init(&mutex, NULL) == 0);
137
assert(pthread_mutex_init(&mutex1, NULL) == 0);
139
/* get current system time */
140
_ftime(&currSysTime);
142
abstime.tv_sec = currSysTime.time;
143
abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
147
assert(pthread_mutex_lock(&mutex1) == 0);
149
for (i = 1; i <= NUMTHREADS; i++)
151
assert(pthread_create(&t[i], NULL, mythread, (void *) i) == 0);
155
assert(pthread_cond_wait(&cv1,&mutex1) == 0);
156
} while ( NUMTHREADS > waiting );
158
assert(pthread_mutex_unlock(&mutex1) == 0);
160
for (i = NUMTHREADS/3; i <= 2*NUMTHREADS/3; i++)
162
// assert(pthread_mutex_lock(&mutex) == 0);
163
assert(pthread_cond_signal(&cv) == 0);
164
// assert(pthread_mutex_unlock(&mutex) == 0);
169
for (i = 1; i <= NUMTHREADS; i++)
171
assert(pthread_join(t[i], (void **) &result) == 0);
175
fprintf(stderr, "awk = %d\n", awoken);
176
fprintf(stderr, "sig = %d\n", signaled);
177
fprintf(stderr, "tot = %d\n", timedout);
179
assert(signaled == awoken);
180
assert(timedout == NUMTHREADS - signaled);
182
assert(pthread_cond_destroy(&cv1) == 0);
185
int result = pthread_cond_destroy(&cv);
188
fprintf(stderr, "Result = %s\n", error_string[result]);
189
fprintf(stderr, "\tWaitersBlocked = %ld\n", cv->nWaitersBlocked);
190
fprintf(stderr, "\tWaitersGone = %ld\n", cv->nWaitersGone);
191
fprintf(stderr, "\tWaitersToUnblock = %ld\n", cv->nWaitersToUnblock);
197
assert(pthread_mutex_destroy(&mutex1) == 0);
198
assert(pthread_mutex_destroy(&mutex) == 0);