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 pthread_cond_broadcast.
39
* Test Method (Validation or Falsification):
42
* Requirements Tested:
52
* - Test broadcast with NUMTHREADS (=5) waiting CVs.
61
* - File name, Line number, and failed expression on failure.
62
* - No output on success.
68
* - Process returns zero exit status.
71
* - Process returns non-zero exit status.
75
#include <sys/timeb.h>
78
* Create NUMTHREADS threads in addition to the Main thread.
84
typedef struct bag_t_ bag_t;
88
/* Add more per-thread state variables here */
91
static bag_t threadbag[NUMTHREADS + 1];
93
typedef struct cvthing_t_ cvthing_t;
96
pthread_cond_t notbusy;
101
static cvthing_t cvthing = {
102
PTHREAD_COND_INITIALIZER,
103
PTHREAD_MUTEX_INITIALIZER,
107
static pthread_mutex_t start_flag = PTHREAD_MUTEX_INITIALIZER;
109
static struct timespec abstime = { 0, 0 };
116
bag_t * bag = (bag_t *) arg;
118
assert(bag == &threadbag[bag->threadnum]);
119
assert(bag->started == 0);
122
/* Wait for the start gun */
123
assert(pthread_mutex_lock(&start_flag) == 0);
124
assert(pthread_mutex_unlock(&start_flag) == 0);
126
assert(pthread_mutex_lock(&cvthing.lock) == 0);
128
while (! (cvthing.shared > 0))
129
assert(pthread_cond_timedwait(&cvthing.notbusy, &cvthing.lock, &abstime) == 0);
131
assert(cvthing.shared > 0);
135
assert(pthread_mutex_unlock(&cvthing.lock) == 0);
145
pthread_t t[NUMTHREADS + 1];
147
struct _timeb currSysTime;
148
const DWORD NANOSEC_PER_MILLISEC = 1000000;
152
assert((t[0] = pthread_self()).p != NULL);
154
assert(cvthing.notbusy == PTHREAD_COND_INITIALIZER);
156
assert(cvthing.lock == PTHREAD_MUTEX_INITIALIZER);
158
assert(pthread_mutex_lock(&start_flag) == 0);
160
_ftime(&currSysTime);
162
abstime.tv_sec = currSysTime.time;
163
abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm;
167
assert((t[0] = pthread_self()).p != NULL);
171
for (i = 1; i <= NUMTHREADS; i++)
173
threadbag[i].started = 0;
174
threadbag[i].threadnum = i;
175
assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0);
179
* Code to control or munipulate child threads should probably go here.
182
assert(pthread_mutex_unlock(&start_flag) == 0);
185
* Give threads time to start.
189
assert(pthread_mutex_lock(&cvthing.lock) == 0);
191
assert(pthread_mutex_unlock(&cvthing.lock) == 0);
193
assert(pthread_cond_broadcast(&cvthing.notbusy) == 0);
196
* Give threads time to complete.
198
for (i = 1; i <= NUMTHREADS; i++)
200
assert(pthread_join(t[i], NULL) == 0);
207
assert(pthread_mutex_destroy(&cvthing.lock) == 0);
209
assert(cvthing.lock == NULL);
211
assert(pthread_cond_destroy(&cvthing.notbusy) == 0);
213
assert(cvthing.notbusy == NULL);
216
* Standard check that all threads started.
218
for (i = 1; i <= NUMTHREADS; i++)
220
failed = !threadbag[i].started;
224
fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started);
231
* Check any results here.
234
assert(awoken == NUMTHREADS);