Wow !!!
Not working!
Producer Code:
while (m_bRun)
{
m_pqThreadMutex->lock();
if (*m_piUsedBytes == MAX_IMATGES)
{
m_pqBufferNotFull->wait(m_pqThreadMutex);
}
m_pqThreadMutex->unlock();
//Put data
m_iIndex = ((m_iIndex+1)%MAX);
m_pqThreadMutex->lock();
(*m_piUsedBytes )++;
m_pqBufferNotEmpty->wakeAll();
m_pqThreadMutex->unlock();
}
m_pqBufferNotEmpty->wakeAll(); //Wake up the Consumer
while (m_bRun)
{
m_pqThreadMutex->lock();
if (*m_piUsedBytes == MAX_IMATGES)
{
m_pqBufferNotFull->wait(m_pqThreadMutex);
}
m_pqThreadMutex->unlock();
//Put data
m_iIndex = ((m_iIndex+1)%MAX);
m_pqThreadMutex->lock();
(*m_piUsedBytes )++;
m_pqBufferNotEmpty->wakeAll();
m_pqThreadMutex->unlock();
}
m_pqBufferNotEmpty->wakeAll(); //Wake up the Consumer
To copy to clipboard, switch view to plain text mode
Consumer Code:
while (m_bRun)
{
m_pqThreadMutex->lock();
if (*m_piUsedBytes == 0)
{
m_pqBufferNotEmpty->wait(m_pqThreadMutex);
}
m_pqThreadMutex->unlock();
if (bRun) //Check if has to be stopped
{
//Get data
m_iIndex = ((m_iIndex+1)%MAX);
m_pqThreadMutex->lock();
(*m_piUsedBytes )--;
m_pqBufferNotFull->wakeAll();
m_pqThreadMutex->unlock();
}
}
while (m_bRun)
{
m_pqThreadMutex->lock();
if (*m_piUsedBytes == 0)
{
m_pqBufferNotEmpty->wait(m_pqThreadMutex);
}
m_pqThreadMutex->unlock();
if (bRun) //Check if has to be stopped
{
//Get data
m_iIndex = ((m_iIndex+1)%MAX);
m_pqThreadMutex->lock();
(*m_piUsedBytes )--;
m_pqBufferNotFull->wakeAll();
m_pqThreadMutex->unlock();
}
}
To copy to clipboard, switch view to plain text mode
For the Producer and Consumer Threads I call "stop()" that changes "bRun" to false. Then I call wait().
void stop_Threads()
{
Producer->stop();
Producer->wait();
Consumer->stop();
Consumer->wait(); //Sometimes it hangs here
}
void stop_Threads()
{
Producer->stop();
Producer->wait();
Consumer->stop();
Consumer->wait(); //Sometimes it hangs here
}
To copy to clipboard, switch view to plain text mode
Bookmarks