Lock CLASS

A process-wide lock that controls access to a certain region in code block.

Julian provides language-level support for using a lock:

   var lock = new Lock();
   sync (lock) {
     ... ... // critical region guarded by the lock.
   }

Parent Class

All Members


TypeNameSignature
constructorLockpublic Lock()
methodlockpublic void lock()
methodnotifypublic void notify()
methodunlockpublic void unlock()
methodwaitpublic bool wait()
methodwaitpublic int wait(int)

Constructors


public Lock()

Create a new lock.


Methods


public void lock()

Apply the lock from the place where this is called.

If the lock is held by other threads, this method will block until the lock is secured.


public void notify()

Notify all the other threads waiting on the lock. The platform will make an arbitrary decision on who will be holding the lock next.

Throw IllegalStateException if the lock is not owned by the current thread.


public void unlock()

Release the lock. Throw IllegalStateException if the lock is not owned by the current thread.


public bool wait()

Wait until acquiring the lock or getting interrupted.

Returns

  • true if the waiting was interrupted and this thread failed to obtain the lock; false if the lock was successfully acquired.

public int wait(int milliSec)

Wait until acquiring the lock, timing out, or getting interrupted.

Parameters

  • milliSec The time to wait on this lock, in milliseconds.

Returns

  • return time spent on waiting in millisec, which must be less than the argument; or 0 if timed out, or -1 if getting interrupted.