|
From: <sv...@va...> - 2007-10-31 19:29:35
|
Author: sewardj
Date: 2007-10-31 19:29:33 +0000 (Wed, 31 Oct 2007)
New Revision: 7065
Log:
Try to ensure this test produces scheduling-invariant results.
Modified:
branches/THRCHECK/thrcheck/tests/tc21_pthonce.c
Modified: branches/THRCHECK/thrcheck/tests/tc21_pthonce.c
===================================================================
--- branches/THRCHECK/thrcheck/tests/tc21_pthonce.c 2007-10-31 18:19:54 UTC (rev 7064)
+++ branches/THRCHECK/thrcheck/tests/tc21_pthonce.c 2007-10-31 19:29:33 UTC (rev 7065)
@@ -51,9 +51,9 @@
printf("welcome: Welcome\n");
unprotected1++; /* this is harmless */
}
-
-void* child ( void* argV ) {
- int r= pthread_once(&welcome_once_block, welcome); assert(!r);
+void maybe_stall ( int myid );
+void* child ( void* argV ) { int r; maybe_stall( *(int*)argV );
+ r= pthread_once(&welcome_once_block, welcome); assert(!r);
printf("child: Hi, I'm thread %d\n", *(int*)argV);
unprotected2++; /* whereas this is a race */
return NULL;
@@ -78,3 +78,14 @@
printf("main: Goodbye\n");
return 0;
}
+
+/* This is a hack: delay threads except the first enough so as to
+ ensure threads[0] gets to the pthread_once call first. This is so
+ as to ensure that this test produces results which aren't
+ scheduling sensitive. (sigh) */
+void maybe_stall ( int myid )
+{
+ assert(myid >= 0 && myid < NUM_THREADS);
+ if (myid > 0)
+ sleep(1);
+}
|