"Alain Ketterlin" schreef in bericht
news:8737b9m...@universite-de-strasbourg.fr.invalid...
I know, but you are missing the point.
A spurious wakeup every nanosecond is not reasonable.
The for loop is there only to limit the output. A while (true) loop would
output millions of lines a time-out simply never happens, because the
wait_for always returns immediately with a no_timeout status.
Do you really think that the following is a valid implementation of
wait_for?
cv_status wait_for (Lock& lck,
const chrono::duration<Rep,Period>& rel_time) {
return cv_status::no_timeout;
}
I don't call that a spurious wake up. But that is effectively what wait_for
is doing in my case.
It constantly returns immediately with a no_timeout status.
That is what I want to demonstrate in this program.
If I do what you say, then there would be a CPU-bound loop for 10 seconds
and the bug would go unnoticed.
(In fact, that was what happened in the original program.)
Please note, that this program is there to demonstrate a bug, not to explain
a good use of wait_for.
Can you explain why the mere presence of pthread_create changes the behavior
of wait_for so drasticly?