#4413 closed Bugs (fixed)
wait_for_any hangs up on empty intervals.
Reported by: | Owned by: | Anthony Williams | |
---|---|---|---|
Milestone: | Boost 1.44.0 | Component: | thread |
Version: | Boost 1.44.0 | Severity: | Problem |
Keywords: | Cc: |
Description
If range based boost::wait_for_any function is called with an empty interval (first == last) then it will hang up forever.
The fix is trivial: if (first == last)
return last;
Change History (4)
follow-up: 3 comment:1 by , 12 years ago
comment:3 by , 12 years ago
Replying to steven_watanabe:
I'm not sure that wait_for_any with an empty range should be supported. Since there are no elements in the range, the conditions under which it should wake up are never satisfied.
The same logic can be applied to a std::find
. If a range is empty, then there are no elements in the range that can satisfy a predicate. So we can hang over, or remove all data on a hard disk...
Please, look at STL - every algorithm that returns an iterator, will return the last iterator (or the first) of the range, and will not hang up. It is idiomatic for algorithms to accept an empty range. This is what most programmers would expect from this function and all other functions that have an iterator based input.
comment:4 by , 12 years ago
std::find is different. Its behavior when the element is not found is specified as returning the end iterator. The empty range isn't a special case.
I'm not sure that wait_for_any with an empty range should be supported. Since there are no elements in the range, the conditions under which it should wake up are never satisfied.