AnalysisContext.EnableConcurrentExecution() - 它到底是做什么的?
AnalysisContext.EnableConcurrentExecution() - what exactly does it do?
我已经阅读了此方法的 documentation,但它在细节上相当简单。
Enable concurrent execution of analyzer actions registered by this analyzer.
到底并发执行了什么?假设我有:
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.InvocationExpression);
}
如果被分析的代码包含多个InvocationExpressions,每个表达式是否会在自己的线程上并发分析?
However, such an analyzer must ensure that its actions can execute correctly in parallel.
什么构成 "action",我如何确保它执行 "correctly"?我的 AnalyzeNode
方法是 static
,从不可变状态读取,不写入任何共享状态。够了吗?
启用并发执行有什么缺点吗?
还是我完全误解了这一点?
If the code under analysis contains multiple InvocationExpressions, will each expression be concurrently analyzed on its own thread?
他们可能确实如此。显然不能保证它们是,只有这么多线程。
What constitutes an "action"
"action" 是您使用 RegisterSyntaxNodeAction
.
等方法注册的委托
My AnalyzeNode
method is static
, reads from immutable state, and does not write to any shared state. Is this enough?
是的。
Are there any drawbacks to enabling concurrent execution?
如果您的操作是读取和写入共享状态,您要么必须同步这些访问,要么不启用并发执行。
我已经阅读了此方法的 documentation,但它在细节上相当简单。
Enable concurrent execution of analyzer actions registered by this analyzer.
到底并发执行了什么?假设我有:
public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.InvocationExpression);
}
如果被分析的代码包含多个InvocationExpressions,每个表达式是否会在自己的线程上并发分析?
However, such an analyzer must ensure that its actions can execute correctly in parallel.
什么构成 "action",我如何确保它执行 "correctly"?我的 AnalyzeNode
方法是 static
,从不可变状态读取,不写入任何共享状态。够了吗?
启用并发执行有什么缺点吗?
还是我完全误解了这一点?
If the code under analysis contains multiple InvocationExpressions, will each expression be concurrently analyzed on its own thread?
他们可能确实如此。显然不能保证它们是,只有这么多线程。
What constitutes an "action"
"action" 是您使用 RegisterSyntaxNodeAction
.
My
AnalyzeNode
method isstatic
, reads from immutable state, and does not write to any shared state. Is this enough?
是的。
Are there any drawbacks to enabling concurrent execution?
如果您的操作是读取和写入共享状态,您要么必须同步这些访问,要么不启用并发执行。