up: THREAD     index Zimbu documentation

CLASS T.lock @public

summary

     

The builtin type lock: An object to get exclusive access.

Useful in multi-threading applications. A Lock object can be used to allow only one thread at a time access. Also known as mutex (MUTual EXclusive).

NEW() @public 
$begin() @public  Block until the lock is obtained.
$tryBegin() status @public  Try obtaining the lock. Return OK when obtained, FAIL when another thread has the lock.
$end() @public  Release the lock. Wakes up threads in wait() for this Lock.
 

members (alphabetically)

     

PROC NEW() @public

PROC $begin() @public

     

Block until the lock is obtained.

When this method returns this thread has exclusive access to what is protected by the Lock. Other threads will have to wait until $end() is called in this thread.

Must always call end() later!

PROC $end() @public

     

Release the lock. Wakes up threads in wait() for this Lock.

Only to be called when the lock was obtained with begin() or tryBegin() earlier!

FUNC $tryBegin() status @public

     

Try obtaining the lock. Return OK when obtained, FAIL when another thread has the lock.

This will never block.

When OK is returned must call end() later!

license

      Copyright 2009 Bram Moolenaar All Rights Reserved.

      Licensed under the Apache License, Version 2.0. See the LICENSE file or obtain a copy at: http://www.apache.org/licenses/LICENSE-2.0