in Operating System retagged by
335 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$
in Operating System retagged by
335 views

1 comment

$ \large{\colorbox{yellow}{Detailed video solution of this question with direct time stamp}}$
All India Mock Test 2 - Solutions Part 2

0
0

Please log in or register to answer this question.