Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2006-08

AW: Lock Free Memory Management

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Helmut Hartl
Show quoted text 7 lines
>> >> Does the Codegenerator already support this? >> Are they portable? >> How would you suggest to implement such operations platform independent? > > I don't think this is possible, as it depends on processor support

?

I think it can be implemented easily using

InterlockedCompareExchange,

no?

Yes it will be but to my knowledge there exists no platform independent version of InterlockedCompareExchange in Free Pascal...and even none for 64Bit.

For a new memory manager there must be a lowlevel function supporting this.
Also this operation must not be reordered/optimized by the compiler.

The operation should preferrably be a
InterlockedCompareExchangePointer()
wich always does the right thing :-) depending on architecture ...

For the interested ...

http://en.wikipedia.org/wiki/Compare-and-swap

http://groups.google.de/group/comp.programming.threads/browse_frm/thread /d062e1bfa460a375/3461ab7dd927a6ec?group=comp.programming.threads#3461ab 7dd927a6ec

helmut

Reply by email

Jonas Maebe
to Helmut Hartl
Helmut Hartl wrote 8 lines
> I think it can be implemented easily using > InterlockedCompareExchange, no? Yes it will be but to my knowledge there exists no platform independent version of InterlockedCompareExchange in Free Pascal...and even none for 64Bit.

It's in the interface of the system unit for 2.1.1

Jonas

Reply by email

Florian Klaempfl
to Helmut Hartl: ? Yes it will be but to my knowledge there exists no platform independent version of…
Helmut Hartl wrote 15 lines
> >> Does the Codegenerator already support this? > >> Are they portable? > >> How would you suggest to implement such operations platform > independent? > > > > I don't think this is possible, as it depends on processor support ? > > I think it can be implemented easily using InterlockedCompareExchange, > no? Yes it will be but to my knowledge there exists no platform independent version of InterlockedCompareExchange in Free Pascal...and even none for 64Bit.

That's true.

Show quoted text 8 lines
For a new memory manager there must be a lowlevel function supporting this. Also this operation must not be reordered/optimized by the compiler. The operation should preferrably be a InterlockedCompareExchangePointer() wich always does the right thing :-) depending on architecture ...

Well, at least on sparc it uses a hidden global lock, so there it's pretty useless :)

Show quoted text 14 lines
For the interested ... http://en.wikipedia.org/wiki/Compare-and-swap http://groups.google.de/group/comp.programming.threads/browse_frm/thread /d062e1bfa460a375/3461ab7dd927a6ec?group=comp.programming.threads#3461ab 7dd927a6ec helmut _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Peter Vreman
to Florian Klaempfl
you wrote 27 lines
Helmut Hartl wrote: > > >> Does the Codegenerator already support this? > > >> Are they portable? > > >> How would you suggest to implement such operations platform > > independent? > > > > > > I don't think this is possible, as it depends on processor support > ? > > > > I think it can be implemented easily using > InterlockedCompareExchange, > > no? > > Yes it will be but to my knowledge there exists no platform independent > version of InterlockedCompareExchange in Free Pascal...and even none for > 64Bit. That's true. > > For a new memory manager there must be a lowlevel function supporting > this. > Also this operation must not be reordered/optimized by the compiler. > > The operation should preferrably be a > InterlockedCompareExchangePointer() > wich always does the right thing :-) depending on architecture ...

Maybe you should first in the RTL code before writing something, from systemh.inc:

function InterLockedIncrement (var Target: longint) : longint; public
name 'FPC_INTERLOCKEDINCREMENT';
function InterLockedDecrement (var Target: longint) : longint; public
name 'FPC_INTERLOCKEDDECREMENT';
function InterLockedExchange (var Target: longint;Source : longint) :
longint; public name 'FPC_INTERLOCKEDEXCHANGE';
function InterLockedExchangeAdd (var Target: longint;Source :
longint) : longint; public name 'FPC_INTERLOCKEDEXCHANGEADD';
function InterlockedCompareExchange(var Target: longint; NewValue:
longint; Comperand: longint): longint; public name
'FPC_INTERLOCKEDCOMPAREEXCHANGE';
{$ifdef cpu64}
function InterLockedIncrement64 (var Target: int64) : int64; public
name 'FPC_INTERLOCKEDINCREMENT64';
function InterLockedDecrement64 (var Target: int64) : int64; public
name 'FPC_INTERLOCKEDDECREMENT64';
function InterLockedExchange64 (var Target: int64;Source : int64) :
int64; public name 'FPC_INTERLOCKEDEXCHANGE64';
function InterLockedExchangeAdd64 (var Target: int64;Source : int64)
: int64; public name 'FPC_INTERLOCKEDEXCHANGEADD64';
function InterlockedCompareExchange64(var Target: int64; NewValue:
int64; Comperand: int64): int64; public name
'FPC_INTERLOCKEDCOMPAREEXCHANGE64';
{$endif cpu64}
{ Pointer overloads }
{$ifdef cpu64}
function InterLockedIncrement (var Target: Pointer) : Pointer;
external name 'FPC_INTERLOCKEDINCREMENT64';
function InterLockedDecrement (var Target: Pointer) : Pointer;
external name 'FPC_INTERLOCKEDDECREMENT64';
function InterLockedExchange (var Target: Pointer;Source : Pointer) :
Pointer; external name 'FPC_INTERLOCKEDEXCHANGE64';
function InterLockedExchangeAdd (var Target: Pointer;Source :
Pointer) : Pointer; external name 'FPC_INTERLOCKEDEXCHANGEADD64';
function InterlockedCompareExchange(var Target: Pointer; NewValue:
Pointer; Comperand: Pointer): Pointer; external name
'FPC_INTERLOCKEDCOMPAREEXCHANGE64';
{$else cpu64}
function InterLockedIncrement (var Target: Pointer) : Pointer;
external name 'FPC_INTERLOCKEDINCREMENT';
function InterLockedDecrement (var Target: Pointer) : Pointer;
external name 'FPC_INTERLOCKEDDECREMENT';
function InterLockedExchange (var Target: Pointer;Source : Pointer) :
Pointer; external name 'FPC_INTERLOCKEDEXCHANGE';
function InterLockedExchangeAdd (var Target: Pointer;Source :
Pointer) : Pointer; external name 'FPC_INTERLOCKEDEXCHANGEADD';
function InterlockedCompareExchange(var Target: Pointer; NewValue:
Pointer; Comperand: Pointer): Pointer; external name
'FPC_INTERLOCKEDCOMPAREEXCHANGE';
{$endif cpu64}

Peter

Reply by email