Skip to contentSkip to conversation

fzsync: Prevent early exit

PATCH New Richard Palethorpe 2 participants 2 messages Oct 31, 2017 – Dec 1, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fzsync: Prevent early exit

From: Richard Palethorpe <[email protected]>

In some tests it may be possible for the child thread to exit before it has completed an equal number of iterations to main thread (the thread which sets the exit state). Due to the way most tests use the library this is unlikely to matter, but in theory it could cause some tests to exit uncleanly. To fix this, we only exit if we find that the thread has progressed to a wait() call which would spin indefinitely if exit were not set.

I already suspected this bug existed, but confirmed while trying to formally verify the algorithm using Modex, see:
https://github.com/richiejp/modex_models

---
 include/tst_fuzzy_sync.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/tst_fuzzy_sync.h +3 -1
index d89f034f0..bcc625e24 100644
@@ -265,7 +265,9 @@ static inline int tst_fzsync_pair_wait(struct tst_fzsync_pair *pair,
 			;
 	}
 
-	return !tst_atomic_load(&pair->exit);
+	/* Only exit if we have done the same amount of work as the other thread */
+	return !tst_atomic_load(&pair->exit) ||
+	  tst_atomic_load(other_cntr) <= tst_atomic_load(our_cntr);
 }
 
 static inline int tst_fzsync_wait_a(struct tst_fzsync_pair *pair)
Signature · 1 line
2.14.2