我正在阅读Michael和Scott关于非阻塞并发队列算法和双锁并发队列算法的论文。他们在论文中提到,测试算法的C代码是可以的来自ftp://ftp.cs.rochester.edu/pub/包/调度意识同步/并发队列。但由于这份报纸非常古老,这种链接不起作用。我从伪代码中编写了C实现,可在http://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html#tlq获得。但是代码中有一些问题。如果有人能解释一下伪代码的pvalue: pointer to data type
部分。我所理解的是Dequeue总是从front或head中提取
dequeue(Q: pointer to queue_t, pvalue: pointer to data type): boolean
//双锁并发队列算法
boolean Dequeue(struct queue_t *queue,int* pvalue)
{
//lock
pthread_mutex_lock(&queue->head_lock);
struct node_t *temp = queue->head;
struct node_t *new_head = temp->next;
if(new_head == NULL)
{
pthread_mutex_unlock(&queue->head_lock);//unlock
return false;
}
*pvalue = new_head->value; // Queue not empty. Read value before release
queue->head = new_head;
pthread_mutex_unlock(&queue->head_lock);// unlock
delete temp;
return true;
}
下面的FTP链接对我来说很好:
ftp://ftp.cs.rochester.edu/pub/packages/sched_conscious_synch/concurrent_queues/concurrent_queues.tar.gz