A lock is one of the very fundamental facilities for concurrency synchronisation that basically ensures certain bit of code is accessed by one thread at a time so this code in a concurrent context is re-entrant or thread-safe. It has close relationship to and sometimes although not very correctly is also known as mutex, critical section.

The behaviour of a lock is easy to understand, a certain contiguous piece of code can be enclosed as a section by the obtaining of a lock as the start and the release of the same lock as the end. Any threads intending to enter this section need to check with the system if it's unlocked and in the case of multiple threads waiting at the same time it's up to the system to decide which should be granted the access once it's unlocked. Whenever a thread is accessing the section it's locked until the thread execution reaches the end of the section and releases the lock and all other waiting threads are blocked at the start of the section.

Last edited Sep 16, 2013 at 2:23 PM by quanben, version 3

Comments

No comments yet.