From ef0952fadae6794e225c0c1654887408bcadbf64 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 6 Jun 2026 18:04:17 +0200 Subject: foo.cpp -> test/threads.cpp --- .github/actions/run-foo/action.yml | 26 ----------------------- .github/actions/run-threads/action.yml | 26 +++++++++++++++++++++++ .github/workflows/test.yml | 16 +++++++------- foo.cpp | 39 ---------------------------------- test/threads.cpp | 39 ++++++++++++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 73 deletions(-) delete mode 100644 .github/actions/run-foo/action.yml create mode 100644 .github/actions/run-threads/action.yml delete mode 100644 foo.cpp create mode 100644 test/threads.cpp diff --git a/.github/actions/run-foo/action.yml b/.github/actions/run-foo/action.yml deleted file mode 100644 index 3167545..0000000 --- a/.github/actions/run-foo/action.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Run foo.exe -description: Run foo.exe and verify its output -runs: - using: composite - steps: - - run: | - $expected = @" - Doing something #1 - Doing something #2 - Doing something #3 - "@ - - $actual = & (Join-Path . foo) - $actual = $actual -join [Environment]::NewLine - - echo @" - Expected output: - $expected - "@ - echo @" - Actual output: - $actual - "@ - - $($actual -eq $expected) -or $(throw "Unexpected output!") - shell: pwsh diff --git a/.github/actions/run-threads/action.yml b/.github/actions/run-threads/action.yml new file mode 100644 index 0000000..fd8e7ae --- /dev/null +++ b/.github/actions/run-threads/action.yml @@ -0,0 +1,26 @@ +name: Run threads.exe +description: Run threads.exe and verify its output +runs: + using: composite + steps: + - run: | + $expected = @" + Doing something #1 + Doing something #2 + Doing something #3 + "@ + + $actual = & (Join-Path . test threads) + $actual = $actual -join [Environment]::NewLine + + echo @" + Expected output: + $expected + "@ + echo @" + Actual output: + $actual + "@ + + $($actual -eq $expected) -or $(throw "Unexpected output!") + shell: pwsh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c9749fd..3c2ffb7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,11 +32,11 @@ jobs: with: platform: '${{ matrix.platform }}' cc: 1 - - name: Build foo.exe + - name: Build threads.exe run: | - & '${{ steps.setup.outputs.gxx }}' -std=c++14 -o foo foo.cpp - - name: Run foo.exe - uses: ./.github/actions/run-foo + & '${{ steps.setup.outputs.gxx }}' -std=c++14 -o (Join-Path . test threads) (Join-Path . test threads.cpp) + - name: Run threads.exe + uses: ./.github/actions/run-threads if: runner.os == 'Windows' - name: Check cc/c++ uses: ./.github/actions/check-cc @@ -67,8 +67,8 @@ jobs: uses: ./.github/actions/check-cc with: version: '${{ matrix.version }}' - - name: Build foo.exe + - name: Build threads.exe run: | - & '${{ steps.setup.outputs.gxx }}' -std=c++14 -o foo foo.cpp - - name: Run foo.exe - uses: ./.github/actions/run-foo + & '${{ steps.setup.outputs.gxx }}' -std=c++14 -o (Join-Path . test threads) (Join-Path . test threads.cpp) + - name: Run threads.exe + uses: ./.github/actions/run-threads diff --git a/foo.cpp b/foo.cpp deleted file mode 100644 index a7891bb..0000000 --- a/foo.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -namespace { - -struct Counter { - std::mutex mtx; - std::size_t impl = 0; -}; - -void do_something(Counter& counter) { - std::lock_guard lck{counter.mtx}; - ++counter.impl; - std::cout << "Doing something #" << counter.impl << '\n'; -} - -} - -int main() { - try { - Counter counter; - std::array workers; - for (auto& worker : workers) { - worker = std::thread{&do_something, std::ref(counter)}; - } - for (auto& worker : workers) { - worker.join(); - } - } catch (const std::exception& e) { - std::cerr << e.what() << '\n'; - return 1; - } - return 0; -} diff --git a/test/threads.cpp b/test/threads.cpp new file mode 100644 index 0000000..a7891bb --- /dev/null +++ b/test/threads.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include +#include +#include + +namespace { + +struct Counter { + std::mutex mtx; + std::size_t impl = 0; +}; + +void do_something(Counter& counter) { + std::lock_guard lck{counter.mtx}; + ++counter.impl; + std::cout << "Doing something #" << counter.impl << '\n'; +} + +} + +int main() { + try { + Counter counter; + std::array workers; + for (auto& worker : workers) { + worker = std::thread{&do_something, std::ref(counter)}; + } + for (auto& worker : workers) { + worker.join(); + } + } catch (const std::exception& e) { + std::cerr << e.what() << '\n'; + return 1; + } + return 0; +} -- cgit v1.3