Explicit Document Locking

There are two types of execution contexts, application and document. All registered commands and reactor callbacks are executed within a document's execution context. Windows messages and callbacks, and some acrxEntryPoint() messages are executed within the application context.

Explicit locking is required only in the application execution context. Locking and unlocking is automatically handled for commands executing in the document context.

Any commands that need to work outside the active document must manually perform document locking using the following lock types.

Locking in the application execution context can be done by calling acDocManager->lockDocument(). The following table describes the four levels of locking options:

Command lock types 

     

Command Lock

Lock Mode

Command Flags

Description

Read only

(not locked)

ACRX_CMD_DOCREADLOCK

For read-only access to objects, locking is not necessary. For example, to open an AcDbObject for Acad::kForRead, or to call acedGetVar(), locking is not necessary.

Exclusive read

AcAp::kRead

ACRX_CMD_DOCREADLOCK

ACRX_CMD_DOCEXCLUSIVELOCK

Using exclusive read mode prevents any other execution context from locking the document for write. This mode guarantees that the document will not be modified during the lock.

Shared write

AcAp::kWrite

(default)

The default lock mode. Multiple execution contexts can hold simultaneous shared write locks. A command can make changes to a document, and when the command is suspended, other commands can make changes to the document.

Exclusive write

AcAp::kXWrite

ACRX_CMD_DOCEXCLUSIVELOCK

Guarantees that your execution context has exclusive access to modify document resources.