SIMPOL Documentation

lock1

Description

lock1 is an intrinsic object type, where objects can be created using lock1.new() or by embedding. lock1 objects are locked by threads, either as an exclusive lock or a shared lock. This object is used to control access to a resource (an object referenced via a variable) that may be shared by more than one thread concurrently.

Type Tags

None

Object Value

The value of an object of type lock1 is undefined and it is an error to attempt to get or to set it.

lock1.new()

Description

A lock created using lock1.new() can be pre-locked. This lock is exclusive and anonymous in the sense that no thread holds the lock, but any thread can release it. The return value is a reference to the new object. Embedded lock1 objects are created without a lock.

Prototype

lock1.new ( boolean locked )

Parameters

ParameterDefault valueType nameDescription
locked.falseboolean If this is equal to .true then the object is locked upon creation.

Properties

PropertyTypeDescription
_type(*) This property is provided for use by the user to attach any object of any type to the type in which this property is provided.
__type(*) This property is provided for use by the user to attach any object of any type to the type in which this property is provided. It has the additional feature of being marked with the resolve keyword, so that object resolution can continue down this property.
typetype Specifies the lock1 type object.

Methods

getexclusive()

Description

The lock will be acquired if no other thread has any lock on this object and there is no anonymous lock on it. A thread can have any number of exclusive locks on each lock1 object, but a single exclusive lock by one thread prevents any sort of lock by any other thread. A thread can have both exclusive and shared locks at the same time. If no lock can be acquired immediately and the value of the block parameter is .true then the thread will not continue until the lock can be acquired. If the lock can never be acquired because one or more other locks are held by threads that cannot release them then the program halts with the error number 73: deadly embrace. The return value is .true or .false, indicating whether or not the lock was acquired.

Prototype

lock1var.getexclusive ( boolean block )

Parameters
ParameterDefault valueType nameDescription
block.trueboolean If the value of this parameter is .true then the thread will block until it can acquire the exclusive lock.

getshared()

Description

The lock will be acquired if no other thread has an exclusive lock on this object and there is no anonymous lock on it. A thread can have any number of shared locks on each lock1 object, and any number of threads can also hold shared locks on the same object at the same time, but a single exclusive lock by one thread prevents any shared lock by any other thread. A thread can have both exclusive and shared locks at the same time. If no lock can be acquired immediately and the value of the block parameter is .true then the thread will not continue until the lock can be acquired. If the lock can never be acquired because one or more exclusive locks are held by threads that cannot release them then the program halts with the error number 73: deadly embrace. The return value is .true or .false, indicating whether or not the lock was acquired.

Prototype

lock1var.getshared ( boolean block )

Parameters
ParameterDefault valueType nameDescription
block.trueboolean If the value of this parameter is .true then the thread will block until it can acquire the shared lock.

release()

Description

This method releases the most recently acquired lock for this thread, or releases the anonymous lock granted at creation time of the lock1 object. If no lock exists that the current thread can release then a fatal error is raised.

Prototype

lock1var.release ()

Parameters

None