Author Topic: Lock/Unlock  (Read 4320 times)

xanatose

  • Member
  • ***
  • Posts: 421
Lock/Unlock
« on: July 09, 2012, 05:05:11 PM »
What assembly instructions are available for creating a lightweight mutex on the same process.

I can use CriticalSection on Win32. But I was wondering if there where assembly instructions that where to accomplish the same thing as a CriticalSection but without the need of calling the API.

Also, How does one implement something similar to the InterlockedIncrement, InterlockedAcquire, etc?

qWord

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: Lock/Unlock
« Reply #1 on: July 09, 2012, 05:41:48 PM »
hi,
What assembly instructions are available for creating a lightweight mutex on the same process.

I can use CriticalSection on Win32. But I was wondering if there where assembly instructions that where to accomplish the same thing as a CriticalSection but without the need of calling the API.
The problem is that you need to wait for the ownership. Using the PAUSE instruction in a wait loop may be a solution.

Also, How does one implement something similar to the InterlockedIncrement, InterlockedAcquire, etc?
The Interlock* functions are implemented using the LOCK-Instruction prefix (see documentation). Also note, that not all functions are available for x86-32/64.
MREAL macros - when you need floating point arithmetic while assembling!

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: Lock/Unlock
« Reply #2 on: July 09, 2012, 07:13:22 PM »
LOCK works - bus lock
certain instructions imply bus lock
i sometimes use XCHG EAX,mem32 for that reason
you can change and read a semaphore at the same time