Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#4413 closed Bugs (fixed)

wait_for_any hangs up on empty intervals.

Reported by: ivg@… 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)

comment:1 by Steven Watanabe, 12 years ago

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.

comment:2 by Anthony Williams, 12 years ago

Resolution: fixed
Status: newclosed

Fixed on trunk

in reply to:  1 comment:3 by ivg@…, 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 Steven Watanabe, 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.

Note: See TracTickets for help on using tickets.