Search code examples
cmultithreadingalgorithmpthreadsconcurrent-programming

Two-Lock Concurrent Queue Algorithm implementation issue


I was going through the paper of Michael and Scott for Non-Blocking Concurrent Queue Algorithm and Two-Lock Concurrent Queue Algorithm. They have mentioned in the paper that C code for the tested algorithms can be ob- tained from ftp://ftp.cs.rochester.edu/pub/ packages/sched conscious synch/concurrent queues. But since the paper is very old the link is not working. I have written the C implementation from pseudocode available at http://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html#tlq . But there are some issues in the code. So, if anyone could explain what this pvalue: pointer to data type part of pseudocode ment. What I understand is Dequeue always extract from front or head what is the pvalue here for

dequeue(Q: pointer to queue_t, pvalue: pointer to data type): boolean

//Two-Lock Concurrent Queue Algorithm

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;
}

Solution

  • The following FTP link works fine for me:

    ftp://ftp.cs.rochester.edu/pub/packages/sched_conscious_synch/concurrent_queues/concurrent_queues.tar.gz