Suggestions to Optimize Blocking Queue implementation
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 ope开发者_如何学Cration 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?
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.
In your current solution, what is the specific problem which you try to achieve by further optimization?
精彩评论