TCriticalSection TryEnter Method Always Returns True

When calling the TryEnter method on TCriticalSection, the result is always right. Of course, this should only be returned if it is capable of capturing the castle?

var
  MyCritSect: TCriticalSection;

begin
  MyCritSect := TCriticalSection.Create;
  try
    //    MyCritSect.Enter;
    Writeln(BoolToStr(MyCritSect.TryEnter, True)); // This should return True
    Writeln(BoolToStr(MyCritSect.TryEnter, True)); // This should return False?
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Even if you uncomment the line MyCritSect.Enter;, it still returns True for both TryEnter calls.

I am using Delphi XE and Windows 10.

+4
source share
1 answer

Critical sections of re-entry blocking . From the doc:

, EnterCriticalSection TryEnterCriticalSection, . , .

TryEnter , , .

+4

Source: https://habr.com/ru/post/1619314/


All Articles