retagged by
433 views
4 votes
4 votes

Consider the scenario where $\text{L}$ is a shared variable which is a pointer to the head of a linked list originally containing three nodes with keys $3, 4,$ and $5.$ Consider the function List_Insert() which is being used by two concurrent threads $\text{T}1$ and $\text{T}2$ of the single process.

Assume that thread $\text{T}1$ invokes $\text{List_Insert(2)},$ and concurrently, thread $\text{T}2$ invokes $\text{List_Insert( 6).}$ 

typedef struct node {
    int key;
    struct node *next;
} node_t;

void List_Insert( int key) {
node_t *new = malloc(sizeof(node_t));
new->key = key;
new->next = L;
L= new;
}

Assuming the successful execution of $\textsf{malloc()},$ and considering the linked list is shared between two processes, what could be the outcomes of the final linked list? 

In each option, the linked list is represented as a sequence of numbers, where the leftmost number signifies the key of the head of the linked list, and elements are separated by commas.

  1. $6,3,4,5$
  2. $6,2,3,4,5$
  3. $2,6,3,4,5$
  4. $2,3,4,5$
retagged by

Please log in or register to answer this question.

Answer:

Related questions

746
views
2 answers
4 votes
GO Classes asked Jan 13
746 views
Consider three concurrently executing threads in the same process using two semaphores $\text{s}1$ and $\text{s2}.$ Assume $\text{s1}$ has been initialized to $1$, while $\text{s2}$ has ... $12$18$36$