Semaphores and the scheduler

  • Preemptive scheduler written in SELF, with support from the virtual machine
  • Semaphores built in SELF.
     
    	semaphore copy
    	semaphore copyBinary
    
  • Understand signal, wait, protect: aBlock
    	lock: semaphore copyBinary.
    	...
    	lock protect: [critical region]
    
  • recursiveSemaphore doesn't block a process that holds the lock

Semaphores and the scheduler

A coroutining primitive allows a preemptive scheduler to be constructed entirely in Self. The scheduling process has special status as a distinguished process.

The scheduler is in a global slot, scheduler. Typing ^C into the controlling terminal window suspends all processing and causes the scheduler to list runnable and sleeping processes; these can be killed, suspended or resumed.

Semaphores are implemented in Self with the cooperation of the scheduler.

Classical semaphores are obtained by sending copy, copyBinary to semaphore. Semaphores understand signal and wait, and can be used to implement critical regions using protect: aBlock (which waits before executing the block, then signals).

A recursiveSemaphore is like a semaphore excepts multiple waits from within the same process count as a single wait. This can be useful in avoiding deadlock.

[ Previous ] [ Index ] [ Next ]