Hi All , I am trying to use concurrent_bounded_queue for a producer/cosumer problem.
I want to have a background thread to collect the garbage. But my code is not working because the blocking "pop()"
never returns even if another thread adds an item to the Queue.
Most probably this could be something to do with my code and understanding . I expect the "push()"to notify the waiting "pop()" thread. Is it so ?
I am posting my basic idea here. Please help.
Thank you.
Zooli
I want to have a background thread to collect the garbage. But my code is not working because the blocking "pop()"
never returns even if another thread adds an item to the Queue.
Most probably this could be something to do with my code and understanding . I expect the "push()"to notify the waiting "pop()" thread. Is it so ?
I am posting my basic idea here. Please help.
Thank you.
Zooli
[bash]class GC
{
private :
tbb::concurrent_bounded_queue nodequeue;
public :
GC()
{
}
void operator()()
{
while(true) {
Item* pItem = 0;
nodequeue.pop(pItem);
delete pItem;
}
}
void finalize(Item* pItem)
{
nodequeue.push(pItem);
}
};
void main()
{
GC gc;
thread thread1(gc);
......
/*Some other threads create and delete "Item" as main thread does below */
......
Item* pItem = create(); /* Main thread also create one item*/
gc.finalize(pItem); /* Main thread adds "Item" for garbage collecton*/
thread1.join();
};
[/bash]
链接已复制
3 回复数