[Contents] [Previous] [Next] [Index]

Lock

Provides a way to lock a critical section of code.

Server-side object

Implemented in

Netscape Server 3.0

Created by

The Lock constructor:

Lock(); 

Parameters

None.

Failure to construct a new Lock object indicates an internal JavaScript error, such as out of memory.

Method Summary

lock
Obtains the lock.

isValid
Verifies that this Lock object was properly constructed.

unlock
Releases the lock.

See also

project.lock, project.unlock, server.lock, server.unlock

Methods

Syntax

lock

Obtains the lock. If someone else has the lock, this method blocks until it can get the lock, the specified timeout period has elapsed, or an error occurs.

Method of

Lock

Implemented in

Netscape Server 3.0

Syntax

lock(timeout)

Parameters

timeout
An integer indicating the number of seconds to wait for the lock. If 0, there is no timeout; that is, the method waits indefinitely to obtain the lock. The default value is 0, so if you do not specify a value, the method waits indefinitely.

Returns

True if it succeeds in obtaining the lock within the specified timeout. False if it did not obtain the lock.

Description

You can obtain a lock for an object to ensure that different clients do not access a critical section of code simultaneously. When an application locks an object, other client requests must wait before they can lock the object.

Note that this mechanism requires voluntary compliance by asking for the lock in the first place.

See also

Lock.unlock, Lock.isValid, project.lock, server.lock

isValid

Verifies that this Lock object was properly constructed.

Method of

Lock

Implemented in

Netscape Server 3.0

Syntax

isValid()

Parameters

None.

Returns

True, if this object was properly constructed; otherwise, false.

Description

It is very rare that your Lock object would not be properly constructed. This happens only if the runtime engine runs out of system resources while creating the object.

Examples

This code creates a Lock object and verifies that nothing went wrong creating it:

// construct a new Lock and save in project 
project.ordersLock = new Lock();
if (! project.ordersLock.isValid()) {
   // Unable to create a Lock. Redirect to error page
   ...
}

See also

Lock.lock, Lock.unlock

unlock

Releases the lock.

Method of

Lock

Implemented in

Netscape Server 3.0

Syntax

unlock()

Parameters

None.

Returns

False if it fails; otherwise, true. Failure indicates an internal JavaScript error or that you attempted to unlock a lock that you don't own.

Description

If you unlock a lock that is unlocked, the resulting behavior is undefined.

See also

Lock.lock, Lock.isValid, project.unlock, server.unlock


[Contents] [Previous] [Next] [Index]

Last Updated: 10/31/97 12:33:29


Copyright � 1997 Netscape Communications Corporation