Re: semaphore locks

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

 



HI nikhil,

> now if in other thread i do not follow the protocol of acquiring a lock
> before access to the global variable and simply write
> //
> //no lock acquired here
>
> a--;
>
> //no lock released here
> //
> Is atomicity lost?
IF you do
a--;
it is not an atomic operation. when split into assempbly nemonics
it will be 3-4 starement before the value of the a isn really decremented..
So is the reason of using semaphores, to accomplisg this atmicity.
Yes, if you do not use semaphores in this context, atimicity might be lost.

> Is the consistency lost?
there is a possibility

> What happens if someone does not follow the standard protocol as in the
> example above?
dare to loose the consistency.

How does this happen:

lets say,
When the no semaphore thread is executing, during 'a--'  there is
process time lapse and kernel schedules another thread i.e. with 'a++'
thread, increments the thread succesfully. and when 'a--' thread runs
again, you will abviously have wrong value.

NOTE: kernel schedules another process when the currenly executing
instrction is completed. 'a--' when atomic is considered a single
instrction by kernel. So, it will not give the control to someone else
before executing it.


> cheers,
> Nikhil
>
>

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at 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