anchor.diff:      Parameter: Pointer;
     end;
   
  +procedure ThreadHeapLock(ThreadHeap: PThreadHeap);
  +var
  +  GlobalStorage: PGlobalStorage;
  +  InternalRecord: PInternalRecord;
  +begin
  +  ThreadHeap.ProcessThreadDeferred;
  +  ThreadHeap.LockFlags := THREAD_HEAP_LOCKABLE;
  +
  +  InternalRecord := CoreInternalRecordPop;
  +  InternalRecord.ThreadHeap := ThreadHeap;
  +  GlobalStorage := Pointer(NativeInt(@GLOBAL_STORAGE[63]) and MASK_64_CLEAR);
  +  GlobalStorage.DeferredThreadHeaps.Push(InternalRecord);
  +end;
  +
   function BrainMMThreadProxy(Parameter: Pointer): Integer;
   var
     ThreadRec: TThreadRec;
  +  ThreadHeap: PThreadHeap;
   begin
     {$ifdef PUREPASCAL}
       CreateThreadHeap(True);
  
positive.code:   ThreadRec := PThreadRec(Parameter)^;
    CoreInternalRecordPush(Parameter);
    Result := ThreadRec.Func(ThreadRec.Parameter);
  end;
  
  procedure BrainMMEndThreadEvent(ExitCode: Integer);
  var
    ThreadHeap: PThreadHeap;
    GlobalStorage: PGlobalStorage;
    InternalRecord: PInternalRecord;
  begin
    ThreadHeap := ThreadHeapInstance;
    {$ifdef PUREPASCAL}
      ThreadHeapInstance := nil;
    {$endif}
  
    ThreadHeap.Lockable := SupposedPtr(True);
    SpinLock(ThreadHeap.Spin);
    try
      ThreadHeap.ProcessThreadDeferred;
    finally
      SpinUnlock(ThreadHeap.Spin);
    end;
  
    InternalRecord := CoreInternalRecordPop;
    InternalRecord.ThreadHeap := ThreadHeap;
    GlobalStorage := Pointer(NativeInt(@GLOBAL_STORAGE[63]) and MASK_64_CLEAR);
    GlobalStorage.DeferredThreadHeaps.Push(InternalRecord);
  end;
  
  {$ifdef FPC}
  
negative.code: begin
    if (P <> nil) then
    begin
      // inline SpinLock
      repeat
        if (Self.FSpin <> 0) then SpinWait(SupposedPtr(Self.FSpin), High(NativeUInt));
      until (0 = AtomicCmpExchange(SupposedPtr(Self.FSpin), 1, 0));
      try
        Self.FreeMemory(P);
      finally
        FSpin := 0; // inline SpinUnlock
      end;
    end;
  end;
  