Given the following code, how would you make it thread-safe?
// basic node structuretypedef struct __node_t { int key; struct __node_t *next;} node_t;
// basic list structure (one used per list)typedef struct __list_t { node_t *head;
} list_t;
void List_Init(list_t *L) { L->head = NULL;}
int List_Insert(list_t *L, int key) {
node_t *new = malloc(sizeof(node_t));
if (new == NULL) { perror("malloc"); return -1; // fail }
new->key = key; new->next = L->head; L->head = new; return 0; // success }
int List_Lookup(list_t *L, int key) { node_t *curr = L->head; while (curr) { if (curr->key == key) { return 0; // success } curr = curr->next; }
}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here