Re: down() and down_interruptible( ) difference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 8/2/06, Deepak Joshi <deepak_cins@xxxxxxxxxxx> wrote:
Hi all,

In case of down_interruptible( ) i read following explination in
understanding linux kernel.

"It is widely used by device drivers since it allows processes that receive
a signal while being blocked on a semaphore to give up the "down" operation.
If the sleeping process is awakened by a signal before getting the needed
resource, the function increments the count field of the semaphore and
returns the value -EINTR. On the other hand, if down_interruptible( ) runs
to normal completion and gets the resource, it returns 0. The device driver
may thus abort the I/O operation when the return value is -EINTR."


so what type of signals they are talking abt ??? and how it is implemented
??
plz explain it to me.

signal here are the signal delivered to user process like a signal to
abort or interrupt etc.
down_interruptible() puts the current process in TASK_INTERRUPTIBLE
state and puts it on semaphore queue of waiting processes and finally
calls schedule() functions to give up CPU to other process, by doing
so current process sleeps till the time state is not changed to
TASK_RUNNING. When a signal is delivered to some process and that
process is in TASK_INTERRUPTIBLE state, kernel changes the state from
TASK_INTERRUPTIBLE to TASK_RUNNING (making them a possible candidate
for selection in next schedule() call).

So by calling down_interruptible() we make sure that the current
process should be waked up either if we get the required resouce or if
we recieve any signal (whichever occurs earlier). On other hand down()
puts the current process in TASK_UNINTERRUPTIBLE state so it only
returns if and only if we are successfull in acquiring a resource.

Its advisable to use down_interruptible() than down() in normal cases.

Gaurav


Thanks and Regards,
Deepak Joshi


 ________________________________
 All new Yahoo! Mail "The new Interface is stunning in its simplicity and
ease of use." - PC Magazine




--
Gaurav
Email: gauravd.chd@xxxxxxxxx
--------------------------------------------
Read my articles at: http://lkdp.blogspot.com
--------------------------------------------
Easy to get air tickets at affordable price,
US to India Air Tickets: www.Ritz-Travel.com
Call at 001-503-848-2299 or mail at info@xxxxxxxxxxxxxxx
--------------------------------------------

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux