我正在阅读Michael和Scott关于非阻塞并发队列算法和双锁并发队列算法的论文。他们在论文中提到测试算法的C代码可以是ob-
来自ftp://ftp.cs.rochester.edu/pub/
包/ sched有意识的同步/并发队列。但由于报纸很旧,链接不起作用。我已经从http://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html#tlq的伪代码编写了C实现。但是代码中存在一些问题。所以,如果有人能够解释这个伪代码的pvalue: pointer to data type
部分是什么。据我所知,Dequeue总是从前面或头部提取
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;
}
答案 0 :(得分:0)