This repository has been archived on 2024-12-25. You can view files and clone it, but cannot push or open issues or pull requests.
OldPascalProjects/OMPSamples/Write Critical.pas
2024-03-10 20:32:51 +03:00

27 lines
875 B
ObjectPascal
Raw Permalink 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.