[fpc-devel] M68k: important milestone reached

Sven Barth pascaldragon at googlemail.com
Mon Feb 24 19:33:41 CET 2014

On 24.02.2014 18:11, Michael Schnell wrote:
> CPI32 (and Fido) has add and sub instruction with memory source and
> Target.:-)

The problem is that InterlockedIncrement and -Decrement return the value 
after increment/decrement. Thus (with interrupts enabled) there could be 
the following problem:

Assume this inline assembly code for InterlockedIncrement (target is the 
"var" argument of the function):

lea target, a0
addq.l (a0), 1
move.l (a0), result
move.l result, target

Now there could be an interupt between addq and move and the OS might 
decide to run a different thread (in case of Linux or Amiga this is 
definitely possible). This other thread *might* do an 
InterlockedIncrement for the same variable as well and might also at 
least finish the addq instruction. Now the first thread can run again 
and the move.l will contain a value after *two* increments. Or worse the 
other thread might have done a InterlockedDecrement and now the target 
value will be the same as before (keep in mind: var parameter!).

Without the possibility to synchronize the access (I include disabling 
interupts here ;) ) there will always be race conditions for 
InterlockedIncrement/-Decrement and the other Interlocked* functions.


More information about the fpc-devel mailing list