<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Edward,</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 6, 2022 at 1:06 AM Edward Liaw via ltp <<a href="mailto:ltp@lists.linux.it" target="_blank">ltp@lists.linux.it</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi, I'm working to get fzsync working with the Android kernel, which<br>
does not have pthread_cancel available.<br>
<br>
In the absence of pthread_cancel, when thread A exits due to a break,<br>
thread B will get stuck in an infinite loop while waiting for thread A<br>
to progress.<br>
<br>
Instead of cancelling thread B, we can use the exit flag to break out of<br>
thread B's loop. This should also remove the need for the wrapper<br>
around the thread.<br></blockquote><div><br></div><div><br></div><div><div class="gmail_default" style="font-size:small">This method is more graceful, but involves a new potential issue.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Looking at tst_fzsync_run_a, if anything goes wrong in other places</div><div class="gmail_default" style="font-size:small">(thread_b) and break with setting 'pair->exit' to 1 to end the looping. </div><div class="gmail_default" style="font-size:small">It doesn't work for thread_a because tst_atomic_store(exit, &pair->exit)</div><div class="gmail_default" style="font-size:small">will reset it back to 0 (int exit = 0). </div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Another suggestion is to distinguish the abnormal invoke for</div><div class="gmail_default" style="font-size:small">tst_fzsync_pair_cleanup, because that is rarely a situation we</div><div class="gmail_default" style="font-size:small">encounter, no need to reset pair->exit over again.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">So better to have this improvement:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">--- a/include/tst_fuzzy_sync.h<br>+++ b/include/tst_fuzzy_sync.h<br>@@ -232,7 +232,11 @@ static inline void tst_fzsync_pair_init(struct tst_fzsync_pair *pair)<br> static inline void tst_fzsync_pair_cleanup(struct tst_fzsync_pair *pair)<br> {<br> if (pair->thread_b) {<br>- tst_atomic_store(1, &pair->exit);<br>+ /* Terminate thread B if parent hits accidental break */<br>+ if (!pair->exit) {<br>+ tst_atomic_store(1, &pair->exit);<br>+ usleep(100000);<br>+ }<br> SAFE_PTHREAD_JOIN(pair->thread_b, NULL);<br> pair->thread_b = 0;<br> }<br>@@ -642,7 +646,6 @@ static inline void tst_fzsync_wait_b(struct tst_fzsync_pair *pair)<br> */<br> static inline int tst_fzsync_run_a(struct tst_fzsync_pair *pair)<br> {<br>- int exit = 0;<br> float rem_p = 1 - tst_timeout_remaining() / pair->exec_time_start;<br> <br> if ((pair->exec_time_p * SAMPLING_SLICE < rem_p)<br>@@ -657,19 +660,18 @@ static inline int tst_fzsync_run_a(struct tst_fzsync_pair *pair)<br> if (pair->exec_time_p < rem_p) {<br> tst_res(TINFO,<br> "Exceeded execution time, requesting exit");<br>- exit = 1;<br>+ tst_atomic_store(1, &pair->exit);<br> }<br> <br> if (++pair->exec_loop > pair->exec_loops) {<br> tst_res(TINFO,<br> "Exceeded execution loops, requesting exit");<br>- exit = 1;<br>+ tst_atomic_store(1, &pair->exit);<br> }<br> <br>- tst_atomic_store(exit, &pair->exit);<br> tst_fzsync_wait_a(pair);<br> <br>- if (exit) {<br>+ if (pair->exit) {<br> tst_fzsync_pair_cleanup(pair);<br> return 0;<br> }<br></div></div><div class="gmail_default" style="font-size:small"><br></div></div><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>