Cisco Interview Question

How would you insert an element into a singly linked list, given that there is also another thread that is iterating over it. (non-blocking)

Interview Answers

Anonymous

Dec 8, 2012

The idea is to only break the link in the list once the element to be inserted is pointing at the rest of the list and pointed to by the previous element. If you broke the list first, you could context switch to the iterating thread and stop iterating because the pointer to the next element wouldn't exist.

1

Anonymous

Jan 10, 2013

Apply mutex on the thread