System单元的TInterfacedObject对象,其中_Addref和_Release实现使用了InterlockedIncrement和InterlockedDecrement函数,这两个函数按照MSDN的说法这些函数不能用在多CPU系统和非X86系统上面。英文原文如下:
The variable pointed to by the lpAddend parameter must be aligned on a 32-bit boundary; otherwise, this function will fail on multiprocessor x86 systems and any non-x86 systems. 我不清楚,在多CPU系统中使用这些函数会带来什么后果,以及Delphi的程序员真的犯下了这些低级错误?欢迎大家讨论。
The variable pointed to by the lpAddend parameter must be aligned on a 32-bit boundary; otherwise, this function will fail on multiprocessor x86 systems and any non-x86 systems. 我不清楚,在多CPU系统中使用这些函数会带来什么后果,以及Delphi的程序员真的犯下了这些低级错误?欢迎大家讨论。
external kernel name 'InterlockedIncrement';function InterlockedDecrement(var Addend: Integer): Integer; stdcall;
external kernel name 'InterlockedDecrement';这个是System单元里面定义的原型,但这两个封装仅仅对Linux系统有效,对于Windows系统,实际上在TInterfacedObject里面调用的是Kernal动态库里面的同名函数....至于楼主说的为什么不适用于非X86系统和多CPU系统,我想应该是这两个函数本身就是线程安全的,就是在当前线程进行引用计数的增减时进行了线程保护,防止了多线程同时操作引起的冲突,所以对于多CPU系统,肯定使用这些函数起不到线程安全的作用。另外对于非X86的系统,我想应该是和CPU结构有关系,静待高论!