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
* --------------------------------------------------------------------------
36
* Test Synopsis: Test cleanup handler executes (when thread is not canceled).
38
* Test Method (Validation or Falsification):
41
* Requirements Tested:
60
* - File name, Line number, and failed expression on failure.
61
* - No output on success.
64
* - have working pthread_create, pthread_self, pthread_mutex_lock/unlock
65
* pthread_testcancel, pthread_cancel, pthread_join
68
* - Process returns zero exit status.
71
* - Process returns non-zero exit status.
74
#if defined(_MSC_VER) || defined(__cplusplus)
79
* Create NUMTHREADS threads in addition to the Main thread.
85
typedef struct bag_t_ bag_t;
89
/* Add more per-thread state variables here */
93
static bag_t threadbag[NUMTHREADS + 1];
100
static sharedInt_t pop_count = {0, {0}};
103
increment_pop_count(void * arg)
105
sharedInt_t * sI = (sharedInt_t *) arg;
107
EnterCriticalSection(&sI->cs);
109
LeaveCriticalSection(&sI->cs);
116
bag_t * bag = (bag_t *) arg;
118
assert(bag == &threadbag[bag->threadnum]);
119
assert(bag->started == 0);
122
/* Set to known state and type */
124
assert(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) == 0);
126
assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0);
129
#pragma inline_depth(0)
131
pthread_cleanup_push(increment_pop_count, (void *) &pop_count);
135
pthread_cleanup_pop(1);
137
#pragma inline_depth()
140
return (void *) result;
148
pthread_t t[NUMTHREADS + 1];
150
InitializeCriticalSection(&pop_count.cs);
152
assert((t[0] = pthread_self()).p != NULL);
154
for (i = 1; i <= NUMTHREADS; i++)
156
threadbag[i].started = 0;
157
threadbag[i].threadnum = i;
158
assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0);
162
* Code to control or munipulate child threads should probably go here.
167
* Give threads time to run.
169
Sleep(NUMTHREADS * 100);
172
* Standard check that all threads started.
174
for (i = 1; i <= NUMTHREADS; i++)
176
if (!threadbag[i].started)
178
failed |= !threadbag[i].started;
179
fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started);
186
* Check any results here. Set "failed" and only print output on failure.
189
for (i = 1; i <= NUMTHREADS; i++)
194
assert(pthread_join(t[i], (void **) &result) == 0);
196
fail = (result == (int) PTHREAD_CANCELED);
200
fprintf(stderr, "Thread %d: started %d: result %d\n",
202
threadbag[i].started,
206
failed = (failed || fail);
211
assert(pop_count.i == NUMTHREADS);
213
DeleteCriticalSection(&pop_count.cs);
221
#else /* defined(_MSC_VER) || defined(__cplusplus) */
229
#endif /* defined(_MSC_VER) || defined(__cplusplus) */