Opened 4 years ago

Closed 3 years ago

#11174 closed Bugs (fixed)

boost::condition_variable::timed_wait with predicate unexpectedly wakes up while should wait infinite

Reported by: zac.sims@… Owned by: viboes
Milestone: Boost 1.60.0 Component: thread
Version: Boost 1.57.0 Severity: Regression
Keywords: Cc:

Description (last modified by viboes)

This is a follow on from the closed bug #9708. boost::condition_variable::timed_wait(..., boost::posix_time::time_duration(boost::posix_time::pos_infin), predicate_type pred) always immediately returns false. The referenced bug suggests this worked in 1.44.

A fix for the non-predicate overload was merged for 1.56 but this wasn't applied for the other overloads of timed_wait.

The current workaround we have is:

bool timeoutReached = false;
if(timeToWait.is_pos_infinity())
{
    waitHandle.wait(lock, boost::bind(&ObjectPool::IsResourceReady, this, boost::ref(waitHandle)));
}
else
{
    // timed_wait returns false if the timeout was reached
    timeoutReached = !waitHandle.timed_wait(lock, timeToWait, boost::bind(&ObjectPool::IsResourceReady, this, boost::ref(waitHandle)));
}

if (timeoutReached)
{
    // handle timeout
}

Change History (9)

comment:1 Changed 4 years ago by viboes

Description: modified (diff)
Owner: changed from Anthony Williams to viboes
Status: newassigned

comment:2 Changed 4 years ago by viboes

Milestone: To Be DeterminedBoost 1.59.0

comment:3 Changed 3 years ago by viboes

Milestone: Boost 1.59.0Boost 1.60.0

comment:4 Changed 3 years ago by viboes

Sorry I missed your ticket. To what other overload are you referring to? What is the type of your timeToWait?

comment:5 Changed 3 years ago by viboes

Milestone: Boost 1.60.0To Be Determined

comment:6 Changed 3 years ago by viboes

PING!!!

comment:7 Changed 3 years ago by zac.sims@…

Sorry for the delayed reply.

timeToWait is a boost::posix_time::time_duration.

I was referring to the predicate overload of timed_wait. Which wasn't fixed in #9708 (see https://github.com/boostorg/thread/commit/68dc454a665a54ab505336860401195dc356fd48#diff-c76416498c6a49103cfc4dbeb4c527e4R363). Seems your April commit has fixed this -- https://github.com/boostorg/thread/commit/385eefd3b3d29a52df89fd95bdc27101010dab69

Can provide a repro (which I should have done in the first place) if it helps close this off?

comment:8 Changed 3 years ago by viboes

Milestone: To Be DeterminedBoost 1.60.0

Thanks for the feedback.

comment:9 Changed 3 years ago by viboes

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.