Changes between Version 3 and Version 4 of kernel_synchro
- Timestamp:
- Oct 8, 2018, 1:00:59 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
kernel_synchro
v3 v4 15 15 == B) busylocks & remote_busylocks == 16 16 17 The '''busylock''' (local) and '''remote_busylock''' (global) are low-level locks implementing a busy-waiting policy for the calling threads. If the lock is already taken by another thread, the calling thread keep polling the lock until success. They are used to protect exclusive higher level synchronisation primitives (such as the ''queuelocks'' or ''rwlocks'' described below) , or ''simple'' data-structure where the accesstime is small and can be bounded.17 The '''busylock''' (local) and '''remote_busylock''' (global) are low-level locks implementing a busy-waiting policy for the calling threads. If the lock is already taken by another thread, the calling thread keep polling the lock until success. They are used to protect higher level synchronisation primitives (such as the ''queuelocks'' or ''rwlocks'' described below) , or ''simple'' data-structure where the locking time is small and can be bounded. 18 18 19 A thread holding a busy lock cannot reschedule. To enforce this rule, the ''busylock_acquire()'' function enter' a critical section before taking the lock, and saves the SR value in the busy lock descriptor. The thread holding the busy lock exit the critical section when it calls the ''busylock_release()'' function that releases the lock and restores the SR state. Each time a thread acquire a busy lock, it increments a busylocks counter in the thread descriptor, and decrements iswhen it releases the lock.19 A thread holding a busy lock cannot deschedule. To enforce this rule, the ''busylock_acquire()'' function enters a critical section before taking the lock, and saves the SR value in the busy lock descriptor. The thread holding the busy lock exit the critical section when it calls the ''busylock_release()'' function that releases the lock and restores the SR state. Each time a thread acquire a busylock, it increments a busylocks counter in the thread descriptor, and decrements it when it releases the lock. 20 20 The scheduler makes a kernel panic if the current thread busylocks counter is not nul when it executes the ''sched_yield()'' function. 21 21 22 To avoid starvation, the ''busylock_acquire()'' function uses a ticket policy: the calling thread makes an atomic increment on a "ticket" allocator in lock descriptor, and keep polling the "current" value until current == ticket. To release the lock, the ''busylock_release()'' function increments the "current" value in lock descriptor.22 To improve fairness, the ''busylock_acquire()'' function uses a ticket policy: the calling thread makes an atomic increment on a ''ticket'' allocator in lock descriptor, and keep polling the ''current'' value until ''current'' == ''ticket''. To release the lock, the ''busylock_release()'' function increments the "current" value in lock descriptor. 23 23 24 24 == C) queuelock & remote_queuelock ==