views:

192

answers:

2

Is the linux kernel's list.h thread safe?

Thanks, Chenz

+3  A: 

No, the list_head struct doesn't contain any lock, and the operations are by no means atomic.

You can see so for yourself here, there is no mention of locking mechanisms etc.

abyx
+4  A: 

Just read the implementation; the answer is clearly NO in the presence of writers. (Multiple readers on immutable data is safe.)

Paul McKenney gives an introduction to RCU on the ever-helpful LWN, from which you can glean some tips on managing thread-safe updates to linked lists. Of course, your usage may be simple enough that spinlocks will suffice.

ephemient