The lock keyword marks a statement block as a critical section by obtaining the mutual-exclusion lock for a given object, executing a statement, and then releasing the lock.
The lock keyword ensures that one thread does not enter a critical section of code while another thread is in the critical section. If another thread tries to enter a locked code, it will wait, block, until the object is released.
The section Threading (C# and Visual Basic) discusses threading.
The lock keyword calls Enter at the start of the block and Exit at the end of the block. A ThreadInterruptedException is thrown if Interrupt interrupts a thread that is waiting to enter a lock statement.Syntax:
private Object thisLock = new Object();
public void Withdraw(decimal amount)
if (amount > balance)
throw new Exception("Insufficient funds");
balance -= amount;
public void RunMe()
static void Main()
ThreadTest b = new ThreadTest();
Thread t = new Thread(b.RunMe);
// Output: RunMe called
Java Enterprise Edition (EE)
Java Standard Edition (SE)
RFC (standard status)
RFC (proposed standard status)
RFC (draft standard status)
RFC (informational status)
RFC (experimental status)
RFC (best current practice status)
RFC (historic status)
RFC (unknown status)
All information of this service is derived from the free sources and is provided solely in the form of quotations.
This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 2938 / . Delta: 0.02100 с