How to use spinlocks
Posted: Sun Aug 31, 2008 12:02 pm
I'm writing multiprocessing support for my OS.
I don't know very well how to use spinlocks, I have some doubts...
For example, if i have a list of tasks, I must acquire a spinlock only when I modify the list (adding or removing a entry) or also when I read data from the list?
And if I have a list of threads inside each task structure, I must acquire a spinlock for each list of thread, or for the list of tasks?
Another small question... Must I disable interrupts when I acquire a spinlock? If yes, why? The spinlock locks the modifying and reading of shared structures, so an interrupt routine can't modify a shared structure (for example the list of tasks) if there is a spinlock that locks the operation. Am I wrong?
I've read a tutorial on spinlocks, but I can't understand very well these two things.
However the tutorial is really good
http://osdev.berlios.de/spinlock_part1.html
http://osdev.berlios.de/spinlock_part2.html
http://osdev.berlios.de/spinlock_part3.html
I don't know very well how to use spinlocks, I have some doubts...
For example, if i have a list of tasks, I must acquire a spinlock only when I modify the list (adding or removing a entry) or also when I read data from the list?
And if I have a list of threads inside each task structure, I must acquire a spinlock for each list of thread, or for the list of tasks?
Another small question... Must I disable interrupts when I acquire a spinlock? If yes, why? The spinlock locks the modifying and reading of shared structures, so an interrupt routine can't modify a shared structure (for example the list of tasks) if there is a spinlock that locks the operation. Am I wrong?
I've read a tutorial on spinlocks, but I can't understand very well these two things.
However the tutorial is really good
http://osdev.berlios.de/spinlock_part1.html
http://osdev.berlios.de/spinlock_part2.html
http://osdev.berlios.de/spinlock_part3.html