Spinlocks question, or some other options?
Posted: Tue May 18, 2010 6:35 am
I think I have to ask: what would spinlocks, or similar single, exclusive-access techniques be good for?
By now, I can only think about it being good for data that must be somehow shared and kept up to date to avoid corruption, with maybe the most obvious case being the filesystem, followed by memory management and task management, as well as communications like in networks, and also maybe synchronization tasks.
But I think, for very specific, but low level code (which seems to be a lot many cases), couldn't the complexity (bug-proneness) of "exclusive-access" algorithms on the data be reduced greatly if things were programmed in a stack approach where, for instance, a shared variable would have its state saved and restored in a stack by all of its users?
Optionally, keeping a record, an "ordered stack" of "callers" so that the last caller be the first to restore the state, which would constitute a classic, common LIFO stack (like the x86 one).
Wouldn't it be better to use a lightweight object-oriented approach as far as practical also, and make several concrete objects contain its "virtual machine" with its "global" shared variables? And finally, decide which "registers" in that object are intended to be used without the need to be saved but with the possibility to do so (which would mimic the freestyle usage of general-purpose CPU registers and could also free them a little) and which others should be saved at all times (and failing to do so would mimic the usage of special registers like stack pointers, general pointers, paging registers, on-memory system structures, control registers and the like which would make everything crash if someone fails to just set/save/restore them properly).
Or how does the x86 CPU manages to run an untold amount of multitasked, multithreaded code with only a few registers which basically save and restore states and a few state-saving structures that are switched to run each task/thread? I think it should be possible to simplify this matter with some design decisions, and these native structures really don't seem to have such complicated "spinlocks", so why don't do things similar to what those x86 structures do already with hardware-grade stability design ideas and with not much (at least not obvious) complexity?
I guess that this stack/hardware-like-virtual-structures approach would only be useful for a reasonable number of register-sized fields, but not for very big data structures (several kilobytes or more but indeed for anything less than that), for speed and space reasons.
Is that one of the reason of the existence of these exclusive access algorithms over the appliance of stack-based algorithms for saving and restoring states? Even so, wouldn't in that case be better to avoid using big shared structures in favor of register-style fields and platform-style structures (compact, efficient and full of consistent optimizations in every detail), and use exclusive-access algorithms only when really needed, like in filesystems and memory/task management, drivers, synchronization or the like?
By now, I can only think about it being good for data that must be somehow shared and kept up to date to avoid corruption, with maybe the most obvious case being the filesystem, followed by memory management and task management, as well as communications like in networks, and also maybe synchronization tasks.
But I think, for very specific, but low level code (which seems to be a lot many cases), couldn't the complexity (bug-proneness) of "exclusive-access" algorithms on the data be reduced greatly if things were programmed in a stack approach where, for instance, a shared variable would have its state saved and restored in a stack by all of its users?
Optionally, keeping a record, an "ordered stack" of "callers" so that the last caller be the first to restore the state, which would constitute a classic, common LIFO stack (like the x86 one).
Wouldn't it be better to use a lightweight object-oriented approach as far as practical also, and make several concrete objects contain its "virtual machine" with its "global" shared variables? And finally, decide which "registers" in that object are intended to be used without the need to be saved but with the possibility to do so (which would mimic the freestyle usage of general-purpose CPU registers and could also free them a little) and which others should be saved at all times (and failing to do so would mimic the usage of special registers like stack pointers, general pointers, paging registers, on-memory system structures, control registers and the like which would make everything crash if someone fails to just set/save/restore them properly).
Or how does the x86 CPU manages to run an untold amount of multitasked, multithreaded code with only a few registers which basically save and restore states and a few state-saving structures that are switched to run each task/thread? I think it should be possible to simplify this matter with some design decisions, and these native structures really don't seem to have such complicated "spinlocks", so why don't do things similar to what those x86 structures do already with hardware-grade stability design ideas and with not much (at least not obvious) complexity?
I guess that this stack/hardware-like-virtual-structures approach would only be useful for a reasonable number of register-sized fields, but not for very big data structures (several kilobytes or more but indeed for anything less than that), for speed and space reasons.
Is that one of the reason of the existence of these exclusive access algorithms over the appliance of stack-based algorithms for saving and restoring states? Even so, wouldn't in that case be better to avoid using big shared structures in favor of register-style fields and platform-style structures (compact, efficient and full of consistent optimizations in every detail), and use exclusive-access algorithms only when really needed, like in filesystems and memory/task management, drivers, synchronization or the like?