There is no way this code will compile.
Beyond that, using an explicit lock object instead of the intrinsic lock allows different methods to use different locks, thereby avoiding contention and exposing the lock externally. In the case of MySemaphore there are only two methods that both lock on the same object, but the approach is still valid. If these methods used the intrinsic lock, then code external to MySemaphore could use a MySemaphore instance as an explicit lock object. That external code and the methods in MySemaphore would then be using the same lock - the intrinsic lock of the MySemaphore instance. The explicit lock object avoids this.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Hi Mandeepsangwan,
Please read what is Semaphore and how it is working :webpage
Regarding your code , I should say basics are not strong , you have declared static methods and doing object level locking !!! How could you mix class level and object level lock .Please read basics of threads .
Thanks ,
Satya
New rule: no elephants at the chess tournament. Tiny ads are still okay.
a bit of art, as a gift, that will fit in a stocking