我希望有两个程序可以相互调用,或者从任何正在运行的线程中被调用,但是一次只能运行一个。我该怎么做?这种方法是否可靠?
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;