views:

40

answers:

2
T BlockingQueue<T>::pop( ) { 
       pthread_mutex_lock(&lock);
       if (list.empty( )) { 
           pthread_cond_wait(&cond) ;
       }
       T temp = list.front( );
       list.pop_front( );
       pthread_mutex_unlock(&lock);
       return temp;
}

The above is the pop operation as defined for a templatized concurrent blocking queue based on an underlying linked list and pthreads. My question: In what ways could we optimize this code further?

+2  A: 

The concurrency handling look pretty minimal. Your underlying container is the best candidate for perf tuning. Is this really a linked list? deque would be better if you are doing FIFO ops only.

EDIT: see also sample code from Anthony Williams (who wrote current Boost.Thread) here, for tips and detailed discussion.

Steve Townsend
+1 for the very useful link.
Chris Jester-Young
A: 

In your current solution, what is the specific problem which you try to achieve by further optimization?

Schedler