<div dir="ltr"><span style="font-size:12.8px">Hi,</span><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">My name is Adhityaa and I'm an undergrad student. This is my first time getting involved in OpenMP development at LLVM. I have used the library a bunch of times before, but I haven't been involved in the behind-the-scenes work before.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">So I was just taking a look at <a href="https://bugs.llvm.org/show_bug.cgi?id=33543" target="_blank">https://bugs.llvm.org/show_<wbr>bug.cgi?id=33543</a> and I tried solving it (it looked like a simple, reproducible bug that looked quite important). First I ran strace on the program to see exactly what was happening - I found that the threads without any tasks were issuing a whole bunch of `sched_yield()`, making the CPU go to 100%.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Then I tried going into the code. I came up with a fairly simple patch that almost solved the issue:</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><div><font face="monospace, monospace">--- kmp_wait_release.h<span style="white-space:pre-wrap">      </span>(revision 313888)</font></div><div><font face="monospace, monospace">+++ kmp_wait_release.h<span style="white-space:pre-wrap">   </span>(working copy)</font></div><div><font face="monospace, monospace">@@ -188,6 +188,7 @@</font></div><div><font face="monospace, monospace">   // Main wait spin loop</font></div><div><font face="monospace, monospace">   while (flag->notdone_check()) {</font></div><div><font face="monospace, monospace">     int in_pool;</font></div><div><font face="monospace, monospace">+    int executed_tasks = 1;</font></div><div><font face="monospace, monospace">     kmp_task_team_t *task_team = NULL;</font></div><div><font face="monospace, monospace">     if (__kmp_tasking_mode != tskm_immediate_exec) {</font></div><div><font face="monospace, monospace">       task_team = this_thr->th.th_task_team;</font></div><div><font face="monospace, monospace">@@ -200,10 +201,11 @@</font></div><div><font face="monospace, monospace">          disabled (KMP_TASKING=0).  */</font></div><div><font face="monospace, monospace">       if (task_team != NULL) {</font></div><div><font face="monospace, monospace">         if (TCR_SYNC_4(task_team->tt.tt_<wbr>active)) {</font></div><div><font face="monospace, monospace">-          if (KMP_TASKING_ENABLED(task_<wbr>team))</font></div><div><font face="monospace, monospace">-            flag->execute_tasks(</font></div><div><font face="monospace, monospace">+          if (KMP_TASKING_ENABLED(task_<wbr>team)) {</font></div><div><font face="monospace, monospace">+            executed_tasks = flag->execute_tasks(</font></div><div><font face="monospace, monospace">                 this_thr, th_gtid, final_spin,</font></div><div><font face="monospace, monospace">                 &tasks_completed USE_ITT_BUILD_ARG(itt_sync_<wbr>obj), 0);</font></div><div><font face="monospace, monospace">+          }</font></div><div><font face="monospace, monospace">           else</font></div><div><font face="monospace, monospace">             this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;</font></div><div><font face="monospace, monospace">         } else {</font></div><div><font face="monospace, monospace">@@ -269,7 +271,7 @@</font></div><div><font face="monospace, monospace">       continue;</font></div><div><font face="monospace, monospace"> </font></div><div><font face="monospace, monospace">     // Don't suspend if there is a likelihood of new tasks being spawned.</font></div><div><font face="monospace, monospace">-    if ((task_team != NULL) && TCR_4(task_team->tt.tt_found_<wbr>tasks))</font></div><div><font face="monospace, monospace">+    if ((task_team != NULL) && TCR_4(task_team->tt.tt_found_<wbr>tasks) && executed_tasks)</font></div><div><font face="monospace, monospace">       continue;</font></div><div><font face="monospace, monospace"> </font></div><div><font face="monospace, monospace"> #if KMP_USE_MONITOR</font></div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Alas, this led to a deadlock - the thread went into a futex wait and was never woke again. So I looked at how GCC did things and they issue a FUTEX_WAKE_PRIVATE for INT_MAX threads at the end of things. This should solve the problem, I think?<br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Anyway, it's pretty late here and I've been at this for over 6-7 hours at a stretch, so I'm really tired. I was just wondering if I could get some help on how to proceed from here (and whether I'm even on the right track).</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Thanks,</div><div style="font-size:12.8px">Adhityaa</div></div>