|
From: <sv...@va...> - 2009-04-16 02:02:56
|
Author: njn
Date: 2009-04-16 03:02:35 +0100 (Thu, 16 Apr 2009)
New Revision: 9564
Log:
Make pth_cvsimple more reliable; it currently fails often on Darwin due to
thread ordering issues.
Modified:
branches/DARWIN/none/tests/pth_cvsimple.c
Modified: branches/DARWIN/none/tests/pth_cvsimple.c
===================================================================
--- branches/DARWIN/none/tests/pth_cvsimple.c 2009-04-16 01:35:29 UTC (rev 9563)
+++ branches/DARWIN/none/tests/pth_cvsimple.c 2009-04-16 02:02:35 UTC (rev 9564)
@@ -12,7 +12,7 @@
* Demonstrates pthread condvars.
*
*/
-
+#include <unistd.h>
#include <stdio.h>
#include <pthread.h>
@@ -65,6 +65,7 @@
pthread_t threads[3];
pthread_create(&threads[0], NULL, watch_count, NULL);
+ sleep(1);
pthread_create(&threads[1], NULL, inc_count, NULL);
pthread_create(&threads[2], NULL, inc_count, NULL);
@@ -77,6 +78,7 @@
// pthread_cond_wait() is never called. Or, we could get a spurious
// wake-up in watch_count(). Nonetheless, it's very likely that things
// will work out as expected, since we're starting watch_count() first.
+ // (Also since the sleep() call was added after watch_count()!)
if (condvar_was_hit == 1)
printf("condvar was hit!\n");
else if (condvar_was_hit > 1)
|