Is the linux kernel's list.h thread safe?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With