M.Joos 30 Posted December 6, 2019 (edited) Hi all, when running the following code program Project105; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, System.SyncObjs; var Sync: Integer; Test: Boolean; begin try TInterlocked.BitTestAndClear(Sync,0); Test := TInterlocked.BitTestAndSet(Sync,0); if Test then writeln('Why is Test true here ??') else writeln('Okay, That''s what I expected'); readln; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. Why is it that the variable Test is set to true, when the documentation says ".... The method returns True if the bit is 1, False otherwise ". Clearly I have set the bit to 0 with TInterlocked.BitTestandClear, haven't I ? What am I missing. Tested with Delphi 10.1 Berlin. Edited December 6, 2019 by M.Joos Share this post Link to post
M.Joos 30 Posted December 6, 2019 1 hour ago, Uwe Raabe said: Works as expected in Rio... You are right, Uwe. Tested it in 10.3.2 and it works as expected. Upon closer inspection it seems they fixed the Tinterlocked code which in Berlin looked like this: $ELSEIF Defined(X86ASM)} asm AND EDX,31 LOCK BTS [EAX],EDX SETNC AL end; {$ELSE} var and in Rio looks like this: {$ELSEIF Defined(X86ASM)} asm AND EDX,31 LOCK BTS [EAX],EDX SETC AL end; {$ELSE} Okay, and I thought I would be crazy or something Share this post Link to post
Alain Weber 0 Posted December 6, 2019 Try Sync := $FFFFFFFF; TInterlocked.BitTestAndClear(Sync, 1); Share this post Link to post