Hi,
I'm trying to develop an application that has 2 Threads. One Thread is a Producer and the other one is a Consumer. The two Threads have acces to two semaphores that lock them like Producer-Consumer algorithm. The Producer insert data into an array and the Consumer reads the data.
Producer code:
Code:
Producer::run() { while (bRun) { m_qUsedData->acquire(); //put data into an array m_iIndex = ((m_iIndex+1)%MAX); //Jump to the next position of the array m_qFreeData->release(); } }
Code:
Consumer::run() { while (bRun) { m_qFreeData->acquire(); //read data from the array and do some work m_iIndex = ((m_iIndex+1)%MAX); //Jump to the next position of the array m_qUsedData->release(); } }
When I stop the program, first I stop the Producer Thread, then the Consumer putting their "bRun" variables to false.
The problem is that if the Consumer is locked into "m_qFreeData->acquire();" they will never exit from "run()" so it will never be really stopped.
The program let's the user to start and stop the threads. When it stopped, other internal changes are made: the Consumer Thread reads images from a Camera and the Camera that we are acquiring images could be changed, so I have to reinitilize the Thread but the main program is stopped into ConsumerThread->wait();
Is there anyway to unlock the Consumer Thread?
I have also tryied to use "tryAcquire()" but it didn't work.
Thanks,

