Pregunta

I'm trying to track a very difficult to reproduce bug. I have a pool of items and use the following to automatically check the pool items back in when the client has finished with them:

typedef std::shared_ptr<T> Handle;

Handle MyPool::checkOut()
{
    static const auto CheckInDeleter = [this](T* item)
    {
        this->checkIn(item);
    };

    return Handle(item, CheckInDeleter);
}

My question is is this unsafe? Will this be assigned to the first pool that checks out an item?

¿Fue útil?

Solución

Yes, static function-scope variables are assigned once,so there will be only one lambda object, that will refer to first MyPool that has checkOut member function called. It is probably not what you need, so just remove static.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top