Previous | Next --- Slide 44 of 66
Back to Lecture Thumbnails
rosalg

The solution utilized a hand over hand method where basically if you are accessing a node in the list, no one else can touch the same node you're touching until you're free

fizzbuzz

Why is it necessary to take a lock on the list? Is this to ensure the head is not removed by some other thread?

stanwie

I am also confused why we still put a lock(list->lock) near the beginning of each function.

jyeung27

I believe it is because we need to start off with locking the list in case any other thread is trying to access the head of the list (think about if there's another thread that wants to delete the head or insert before it). We don't want those computations to interfere with our iterating over a list while we are trying to insert/delete somewhere else further down the linked list.

fizzbuzz

@jyeung27 why wouldn’t the lock on the list head itself handle this case?

Ethan

I think lock on the list is equivalent to lock on the head. See WA4 Practice 3 soln.

Please log in to leave a comment.