在Windows平台上,通过调用Windows API EnterCriticalSection / LeaveCriticalSection来实现TCriticalSection. Microsoft文档明确指出,在线程拥有关键部分的所有权后,它可以对EnterCriticalSection进行额外调用.
到现在为止还挺好.
但是Delphi支持的其他平台下的行为如OSX,iOS和Android呢?
其他平台似乎使用TMonitor.所以这个问题可以改写为TMonitor.
最佳答案
在除Windows之外的其他平台上实施TCriticalSection只使用TMonitor.因此,您的问题的答案减少了TMonitor.Enter的行为.至少文档说明TMonitor.Enter是可重入的.
documentation的这一部分对你的答案意味着“是”:
Prohibits the access of all other threads but the calling one to the specified object.
TMonitor的相关代码部分位于TMonitor.TryEnter:
function TMonitor.TryEnter: Boolean;
begin
if FOwningThread = GetCurrentThreadId then // check for recursion
begin
...
Result := True;
...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。