-1
我正在閱讀Michael和Scott關於非阻塞併發隊列算法和雙鎖併發隊列算法的文章。他們在文章中提到,測試算法的C代碼可以從ftp://ftp.cs.rochester.edu/pub/ 包/ sched有意識的同步/併發隊列獲得。但由於論文太舊,鏈接無法正常工作。我從http://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html#tlq的僞代碼中編寫了C實現。但是代碼中存在一些問題。那麼,如果任何人都可以解釋一下這個僞碼的部分是什麼pvalue: pointer to data type
。我的理解是出隊總是從正面提取或頭什麼是p值這裏雙鎖併發隊列算法實現問題
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;
}
我建議關閉這個問題,並創建一個新的描述您的代碼與您的問題。 –
@CoryNelson當然,或者我可以把我的代碼放在同一個線程中 – Pan