Thread Synchronization
·The simplest way to provide mutually exclusive access to
an object shared between threads
is to use lock:
lock(someObject) {
// do some processing
on
// someObject
}
While a thread is
processing the code inside the lock statement no other thread is allowed to access someObject.