<div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_extra"><br><div class="gmail_quote">Jan Stancek <span dir="ltr"><<a href="mailto:jstancek@redhat.com" target="_blank">jstancek@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This test sets priorities, measures time, tries to synchronize<br>
threads with integers and sleeps for seconds. And there appears<br>
to be race somewhere that makes it rarely fail.<br>
<br>
The premise tested is that action triggered by pthread_cancel<br>
runs asynchronously. This rewrite takes simpler approach:<br>
<br>
Thread sleeps until it can observe variable set by parent<br>
_after_ pthread_cancel() or after it hits specified timeout.<br>
If timeout is hit, then presumably cleanup_func() didn't<br>
run in parallel with main thread and test fails.<br>
<br>
Signed-off-by: Jan Stancek <<a href="mailto:jstancek@redhat.com">jstancek@redhat.com</a>><br><div style="font-size:small;display:inline" class="gmail_default">[...]<br></div><br>
+int main(void)<br>
+{<br>
+ pthread_t th;<br>
+<br>
+ SAFE_PFUNC(pthread_mutex_lock(<wbr>&mutex));<br>
+ SAFE_PFUNC(pthread_create(&th, NULL, thread_func, NULL));<br>
+<br>
+ /* wait for thread to start */<br>
+ SAFE_PFUNC(pthread_mutex_lock(<wbr>&mutex));<br>
+ SAFE_PFUNC(pthread_cancel(th))<wbr>;<br>
+<br>
+ /*<br>
+ * if cancel action would run synchronously then<br>
+ * thread will sleep for too long, because it<br>
+ * would never see after_cancel == 1<br>
+ */<br>
+ after_cancel = 1;<br>
+<br>
+ SAFE_PFUNC(pthread_join(th, NULL));<br>
+<br>
+ if (thread_sleep_time >= TIMEOUT_MS) {<br></blockquote><div><br></div><div><div style="font-size:small" class="gmail_default">Since the 'cleanup_flag' was removed, how can we know <div style="font-size:small;display:inline" class="gmail_default"></div>cleanup_func()</div><div style="font-size:small" class="gmail_default">will definitely be called? here if the thread_sleep_time == 0, we also get pass from this test.<br></div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ printf("Error: thread hit timeout\n");<br>
+ exit(PTS_FAIL);<br>
+ }<br>
+<br></blockquote><div><br></div><div><div style="font-size:small" class="gmail_default">Maybe add:</div><div style="font-size:small" class="gmail_default"> SAFE_PFUNC(pthread_mutex_unlock(&mutex));<br></div><div style="font-size:small" class="gmail_default">here too?</div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+ printf("Thread cancelled after %d ms.\n", thread_sleep_time);<br>
+ printf("Test PASSED\n");<br>
+ exit(PTS_PASS);<br>
+}<br>
<span class="gmail-HOEnZb"><font color="#888888"><br></font></span></blockquote><div><br></div><div style="font-size:small" class="gmail_default">Otherwise looks good to me.</div></div><br clear="all"><br>-- <br><div class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div>
</div></div>