pascalabcnet/TestSuite/CompilationSamples/Write Critical.pas

27 lines
875 B
ObjectPascal
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Вывод в параллельной секции без использования критических секций
// и с их использованием. В первом случае из-за параллельного доступа
// к разделяемому ресурсу возможно, что строки будут выводиться
// на одной строке, и в произвольно порядке. Во втором случае такого не будет.
begin
{$omp parallel sections}
begin
begin
WriteLn('Thread 1 started');
end;
begin
WriteLn('Thread 2 started');
end;
end;
{$omp parallel sections}
begin
begin
{$omp critical a}
WriteLn('Thread 1 started');
end;
begin
{$omp critical a}
WriteLn('Thread 2 started');
end;
end;
end.