<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 30, 2021 at 5:32 PM Joerg Vehlow <<a href="mailto:lkml@jv-coder.de">lkml@jv-coder.de</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<br>
<br>
On 7/30/2021 11:12 AM, Cyril Hrubis wrote:<br>
> Hi!<br>
>> On musl, pthread_kill() doesn't return ESRCH if thread id is not found<br>
>> (POSIX only recommends to return ESRCH). Use tst_atomic_store/load()<br>
>> instead, when waiting for the thread.<br>
>><br>
>> Also, the thread's resources wasn't properly freed after the run(),<br>
>> so adding pthread_join() should fix that.<br>
> I do not think that we even need atomic operations here as we do not<br>
> have competing threads setting the value, it should work fine with<br>
> regular assignments as long as the completed variable is marked as<br>
> volatile (which will prevent compiler mis-optimizations).<br>
<br>
+1 Using a volatile variable should be enough here.<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">I have no preference for atomic or volatile methods.</div><div class="gmail_default" style="font-size:small">Both should be fine.</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">
If only pthread_timedjoin_np was not _np... This is exactly the function <br>
that could be used here without any boilerplate.<br>
But is the custom timeout handling in this test even required? Does the <br>
default timeout using SIGALRM not work?<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">The default timeout obviously works.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="">But with introducing the thread_B (custom timeout) can get a fine-grained</div><div class="gmail_default" style="">report when the read() was stuck. That's the advantage I can think of.</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">
The thread was introduced, because SIG_ALRM was apparently not able to <br>
interrupt the read call on linux < 4.14.<br>
But even there it should be possible to interrupt pthread_join. So just <br>
replacing the whole loop with pthread_join should be enough.<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">That should work but no precise log to indicate where goes wrong,</div><div class="gmail_default" style="font-size:small">so I vote to go the loop way:).</div></div></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>