On 12/21/05, pradeep singh <2500.pradeep@xxxxxxxxx> wrote: > > > On 12/22/05, Jesper Juhl <jesper.juhl@xxxxxxxxx> wrote: > > On 12/21/05, pradeep singh <2500.pradeep@xxxxxxxxx> wrote: > > > > > > > > > On 12/21/05, Badari Prasad <h.badari@xxxxxxxxx > wrote: > > > > Hello, > > > > I have a Query regarding semaphores, is semaphores a > mandatory > > > lock mechanism ( like lockf() ) ,or an advisory lock mechanism ( like > flock > > > () ). > > > > > > it is a mandatory lock mechanishm , where the requesting process > checks > > > for a value to get positive ( as semaphores r initalised to a value > > > depending on usage ...AFAIR ..plz CMIIW) , there r generally 2 > operations on > > > them. > > > > > > > [Please: s/r/are/ , s/plz/please/] > > > > You are wrong. Kernel semaphores are, as Matthew Wilcox already > > answered, advisory locks. > > Nothing at all is stopping you from accessing data protected by a > > semaphore - bad things will probably happen but nothing stops you from > > crashing your kernel that way. > > thanks a lot jesper for correcting me:-) > > but i read every process which has to enter cetain block of code protected > by semphore( say a binary semaphore ) will 1st check for the value of the > sempahore and if its is 0 then increment it to 1 and eneter d block and > subsequently decrement d value to 0 when leaving the block, right ?? > If it's properly written it'll use the semaphore to ensure it's not stepping on someone elses toes, yes. > now how can other process get inside the block without actually > incrementing the semaphore to one?? ... > if a section of code is written with proper checking/taking of the lock can of course not execute that secific code section without the proper locking being done, but you could (this is silly, but you can do it) simply use a jmp instruction to jump into the middle of the section, bypassing the code checking the semaphore. If it's some bit of data that the semaphore protects you can simply access the data without checking the semaphore first. In a nutshell: for semaphores (or advisory locks in general) to work correctly, all code that access the data/code paths they protect need to be written to properly check/take the lock, but nothing stops you from writing code that ignore the lock - your code will be buggy, but the compiler will build it and the CPU will run it. > plz explain. > hmm, I guess the [Please: s/r/are/ , s/plz/please/] bit from the last mail didn't sink in ;-) > thanks a lot :-) > You're welcome. -- Jesper Juhl <jesper.juhl@xxxxxxxxx> Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html Plain text mails only, please http://www.expita.com/nomime.html -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/