我希望有两个可以相互调用的过程,或者从正在运行的任何线程中调用,但一次只能运行一个。我怎样才能做到这一点?这会正常工作吗?
var
cs: TCriticalSection;
procedure a;
begin
cs.Acquire;
try
// Execute single threaded here.
finally
cs.Release;
end;
end;
procedure b;
begin
cs.Acquire;
try
// Execute single threaded here. Maybe with calls to procedure a.
finally
cs.Release;
end;
end;