aboutsummaryrefslogtreecommitdiff
path: root/pthreads/tests/once3.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2013-02-13 10:41:10 +0100
committermarha <marha@users.sourceforge.net>2013-02-13 10:41:10 +0100
commitb41f74438672dd682bc01ae818cb3da654f22c1e (patch)
tree07674ef1368a5427a75080528d8cee74234f6b28 /pthreads/tests/once3.c
parentaaf21968deb85b635cb6aa6544df233ea5981346 (diff)
downloadvcxsrv-b41f74438672dd682bc01ae818cb3da654f22c1e.tar.gz
vcxsrv-b41f74438672dd682bc01ae818cb3da654f22c1e.tar.bz2
vcxsrv-b41f74438672dd682bc01ae818cb3da654f22c1e.zip
Updated to latest CVS version of pthreads
Diffstat (limited to 'pthreads/tests/once3.c')
-rw-r--r--pthreads/tests/once3.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/pthreads/tests/once3.c b/pthreads/tests/once3.c
index ef1229043..6c7728607 100644
--- a/pthreads/tests/once3.c
+++ b/pthreads/tests/once3.c
@@ -6,10 +6,11 @@
*
* Pthreads-win32 - POSIX Threads Library for Win32
* Copyright(C) 1998 John E. Bossom
- * Copyright(C) 1999,2005 Pthreads-win32 contributors
- *
- * Contact Email: rpj@callisto.canberra.edu.au
- *
+ * Copyright(C) 1999,2012 Pthreads-win32 contributors
+ *
+ * Homepage1: http://sourceware.org/pthreads-win32/
+ * Homepage2: http://sourceforge.net/projects/pthreads4w/
+ *
* The current list of contributors is contained
* in the file CONTRIBUTORS included with the source
* code distribution. The list can also be seen at the
@@ -60,8 +61,8 @@ typedef struct {
CRITICAL_SECTION cs;
} sharedInt_t;
-static sharedInt_t numOnce = {0, {0}};
-static sharedInt_t numThreads = {0, {0}};
+static sharedInt_t numOnce;
+static sharedInt_t numThreads;
void
myfunc(void)
@@ -72,7 +73,7 @@ myfunc(void)
LeaveCriticalSection(&numOnce.cs);
/* Simulate slow once routine so that following threads pile up behind it */
Sleep(10);
- /* test for cancelation late so we're sure to have waiters. */
+ /* Test for cancellation late so we're sure to have waiters. */
pthread_testcancel();
}
@@ -81,12 +82,18 @@ mythread(void * arg)
{
/*
* Cancel every thread. These threads are deferred cancelable only, so
- * only the thread performing the once routine (my_func) will see it (there are
- * no other cancelation points here). The result will be that every thread
- * eventually cancels only when it becomes the new 'once' thread.
+ * this thread will see it only when it performs the once routine (my_func).
+ * The result will be that every thread eventually cancels only when it
+ * becomes the new 'once' thread.
*/
assert(pthread_cancel(pthread_self()) == 0);
+ /*
+ * Now we block on the 'once' control.
+ */
assert(pthread_once(&once[(int)(size_t)arg], myfunc) == 0);
+ /*
+ * We should never get to here.
+ */
EnterCriticalSection(&numThreads.cs);
numThreads.i++;
LeaveCriticalSection(&numThreads.cs);
@@ -98,7 +105,16 @@ main()
{
pthread_t t[NUM_THREADS][NUM_ONCE];
int i, j;
+
+#if defined(PTW32_CONFIG_MSVC6) && defined(__CLEANUP_CXX)
+ puts("If this test fails or hangs, rebuild the library with /EHa instead of /EHs.");
+ puts("(This is a known issue with Microsoft VC++6.0.)");
+ fflush(stdout);
+#endif
+ memset(&numOnce, 0, sizeof(sharedInt_t));
+ memset(&numThreads, 0, sizeof(sharedInt_t));
+
InitializeCriticalSection(&numThreads.cs);
InitializeCriticalSection(&numOnce.cs);
@@ -108,7 +124,9 @@ main()
for (i = 0; i < NUM_THREADS; i++)
{
- assert(pthread_create(&t[i][j], NULL, mythread, (void *)(size_t)j) == 0);
+ /* GCC build: create was failing with EAGAIN after 790 threads */
+ while (0 != pthread_create(&t[i][j], NULL, mythread, (void *)(size_t)j))
+ sched_yield();
}
}