Some loops might never yield
Imported from http://bugzilla.roxen.com/bugzilla/show_bug.cgi?id=1237
Reported by Martin Stjernholm mast@roxen.com
The following program will never print "stop" and terminate:
int i = 1;
int main()
{
thread_create (lambda ()
{
while (i) sleep (0.02);
});
werror ("start\n");
sleep (1);
werror ("stop\n");
exit (0);
}
The reason is that the loop in the thread never yields when the sleep is short enough, so the main thread won't get to run again.
If the short sleep is increased to 0.03, it works. If it's replaced with a non-sleep, e.g. i++, it also works.
This problem exists in all 7.x versions.