二锁并发队列算法实现问题
Two-Lock Concurrent Queue Algorithm implementation issue
我正在阅读 Michael 和 Scott 的非阻塞并发队列算法和双锁并发队列算法的论文。他们在论文中提到,用于测试算法的 C 代码可以被 ob-
来自 ftp://ftp.cs.rochester.edu/pub/
packages/sched 有意识地 synch/concurrent 队列。但是由于这篇论文很旧,所以 link 不起作用。我已经从 http://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html#tlq 提供的伪代码编写了 C 实现。但是代码中存在一些问题。所以,如果有人能解释伪代码的 pvalue: pointer to data type
部分是什么。我的理解是 Dequeue 总是从 front 或 head 中提取这里的 pvalue for
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;
}
我正在阅读 Michael 和 Scott 的非阻塞并发队列算法和双锁并发队列算法的论文。他们在论文中提到,用于测试算法的 C 代码可以被 ob-
来自 ftp://ftp.cs.rochester.edu/pub/
packages/sched 有意识地 synch/concurrent 队列。但是由于这篇论文很旧,所以 link 不起作用。我已经从 http://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html#tlq 提供的伪代码编写了 C 实现。但是代码中存在一些问题。所以,如果有人能解释伪代码的 pvalue: pointer to data type
部分是什么。我的理解是 Dequeue 总是从 front 或 head 中提取这里的 pvalue for
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;
}