Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 616
Crazy Chenz Avatar asked Nov 25 '09 22:11

Crazy Chenz


2 Answers

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.

like image 69
abyx Avatar answered Oct 06 '22 00:10

abyx


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.

like image 31
ephemient Avatar answered Oct 06 '22 00:10

ephemient