Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

concurrent_bounded_queue usage

zoolii
Beginner
144 Views
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
[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]
0 Kudos
3 Replies
zoolii
Beginner
144 Views
Hi All,

Anybody?.

Thank you
Zooli
jimdempseyatthecove
Black Belt
144 Views
Zooli

There is a TBB forum which will be more appropriate for your query.

Jim
zoolii
Beginner
144 Views

Thank you Jim, I am posting it to TBB forum.

Reply