Most of the time objects are accessed synchronously and don?t need any mechanism to prevent data corruption, but sometimes when you are running in a multithreaded environment, you have to ensure that the single thread don?t access data simultaneously.

ObjAsm32 introduces xCall and xACall to implement the serialized access to object methods.
This approach lets the programmer choose the best method  invocation mode depending on what is intended, avoiding the overhead of the serialization in case of a synchronous code.

The impact on the code is minimal, since there are 3 changes to perform

  • 1. The MethodEnd macro supports now an additional parameter that describes the register that contains information on method exit. These registers are preserved over the synchronization process.

  • 2. Object intended to work with xOCall and xACall need a variable called pCritSect initialized to NULL.

  • 3. If the object will be used to work asynchronously, the serialization must be started using the EnableAsyncAccess macro.

The following lines are an example how to use it:

Method StringManager.Init, uses esi, pOwner:Pointer
    SetObject esi
    EnableAsyncAccess, ASM_OUTOFMEMORY

Here all accesses to the StringManager are locked until the Concat method finishes:

xOCall .pStrMgr::StringManager.Concat, eax, ecx

Attached is the prerelease of the file and some affected objects.


Posted on 2006-11-08 05:03:10 by Biterider
Great invention! Keep going on!
Posted on 2006-11-09 01:05:53 by guidry