Closed requested to merge 3v1n0/glib:thread-pool-slow-starving-fix into main
In order to avoid possibly failures we are now waiting for all threads to have completed before stopping the unused ones, however we're waiting using a sleep call that may actually make the waiting threads not have the opportunity to run, leaving us just waiting indefinitely.
To avoid this, let's instead yield to give the waiting threads a chance to run while we're waiting.
Fixes: #2685 (closed)
It seems that same could be achieved by just iterating (i.e.
while ((guint) g_atomic_int_get (&n_threads_executed) < limit) \n ;), but I think this is more correct, as even a simple busy-loop could lead to hit the same situation.