Re: [Geekos-devel] Efficient implementing of semaphores...
Status: Pre-Alpha
Brought to you by:
daveho
From: David H. <da...@cs...> - 2003-02-03 14:28:03
|
On Sun, Feb 02, 2003 at 01:46:18PM -0500, Jaime Lafleur-Vetter wrote: > Yes, indeed there is. > > Most architectures provide at least one atomic instruction that would > enable you to implement critical sections and semaphore without having > to resort to disabling interrupts. > > Example instructions that the hardware may provide atomically are: > Test-and-set: operates on 1 bit of memory. Returns the > previous value and sets the bit to 1. > Swap: swaps to input values > > Since these operations would be atomic, they could be used to enforce a > critical section. The tricky part comes in determining what to do if the atomic instruction determines that the lock is held (i.e., another thread is in the critical section). It could yield the CPU and retest the condition again when it wakes up. However, you have to ensure that while the thread is trying to put itself to sleep, the lock isn't released, resulting in the thread possibly sleeping forever! I think to solve this problem, the scheduler would need to be aware of threads that had partially completed lock operations in progress. > In GeekOS disabling of interrupts for atomicity is used in many places > because the time period where interrupts are disabled is so small that > it has little or no negative effect. Thus, I wouldn't be concerned with > disabling of interrupts as long as the period is short. I think this is probably true, but allowing GeekOS to support a locking style where interrupts could remain enabled would be nice. -Dave |