android – 一个线程可以安全地多次调用TCriticalSection.Acquire吗?

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;
  ...

相关文章

AdvserView.java package com.earen.viewflipper; import an...
ImageView的scaleType的属性有好几种,分别是matrix(默认)...
文章浏览阅读8.8k次,点赞9次,收藏20次。本文操作环境:win1...
文章浏览阅读1.2w次,点赞15次,收藏69次。实现目的:由main...
文章浏览阅读3.8w次。前言:最近在找Android上的全局代理软件...
文章浏览阅读2.5w次,点赞17次,收藏6次。创建项目后,运行项...