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.
- $6,3,4,5$
- $6,2,3,4,5$
- $2,6,3,4,5$
- $2,3,4,5$