suppose we have multi processor machine and multi threaded application. If two threads have access to a synchronized method and they got executed at the same time which thread will gets the lock? or what will happen?
Thanks
suppose we have multi processor machine and multi threaded application. If two threads have access to a synchronized method and they got executed at the same time which thread will gets the lock? or what will happen?
Thanks
The point is that there is no such thing as "at the same time". One of the two will get the lock, but you have no way to know which one.
There is no such thing "at at the same time" because, liberally speaking, a lock is something that chooses and executes the threads one at a time exclusively.
This is naturally accomplished in a pure monoprocessor system that can execute one instruction at a time. On multiprocessor systems usually there is some hardware device that "locks" the processors to prevent them from executing at the same time.