lundi 23 novembre 2020

Thread safe queue implementation : Efficient implementation of pop()

I am trying to implement thread safe version of queue and facing problem in implementing wrapper around pop(). Refer code below. Can't paste entire code due to restriction.

bool internal_pop_front_no_lock(T& item)
{
    bool isDataAvailable = false;

    if (!m_Queue.empty())
    {
        item = m_Queue.front();
        m_dataQueue.pop();
        isDataAvailable = true;
    }

   return isDataAvailable;
}

Now I feel the line item = m_Queue.front(); will make a copy of data. Is there a way I can avoid copy? or am I misunderstanding something?

Aucun commentaire:

Enregistrer un commentaire