Boost logo

Boost :

Subject: Re: [boost] [thread] basic mutex problem
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2011-08-13 06:30:06


On 08/12/2011 07:59 PM, Greg Rubino wrote:

> struct random_activity_planner {
>
> random_activity_planner(vector<activity>& a, posix_time::ptime o)
> : activities(a)
> , origin(o) {}
>
> void operator()() {
>
> g_mutex.lock();
> posix_time::ptime start(origin + posix_time::seconds(rand() % 1000));
> posix_time::ptime end(start + posix_time::seconds(rand() % 1000));
> activities.push_back(activity(start, end));
> g_mutex.unlock();
>
> }
>
> vector<activity>& activities;
> const posix_time::ptime& origin;
>
> };

You store a dangling reference to a temporary object in the
random_activity_planner::origin. Thus the result of operator() is undefined.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk