Monday 22 August 2011

Concurrency management


1. semaphores and mutex;
context: kernel threads. the thread should be in sleep state for sometimes so as to perform its necessary tasks.
init_MUTEX
down_interruptible
up

2.completion : Allowing one thread to tell another that the job is done
context : interrupt handlers. we are doing some actions and we should expect its reaction from the hardware and which is an immediate reaction then we can use completion. example waiting for command completion interrupt from hardware.
init_completion
wait_for_completion
complete
3.spinlock
context: atomic, interrupt handlers
spin_lock_init
spin_lock_irqsave
spin_unlock_restore

spinlock : single holder lock.if you can't get the spinlock, you keep trying (spinning) until you can.The code written within the locking should be atomic (it should not sleep otherwise it should not given up the processor). If so the deadlock will occur.

semaphores: more than one holder but commonly used as single holder  lock(mutex).If you can't get a semaphore, your task will put itself on the queue, and be woken up when the semaphore is released. This means the CPU will do something else while you are waiting.

No comments:

Post a Comment