diff options
Diffstat (limited to '')
-rw-r--r-- | .github/workflows/test.yml | 23 | ||||
-rw-r--r-- | foo.cpp | 39 |
2 files changed, 61 insertions, 1 deletions
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e5118cc..bf87d6b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,6 +43,10 @@ jobs: - name: Checkout uses: actions/checkout@v2 + - name: Clean up PATH + uses: egor-tensin/cleanup-path@v1 + if: runner.os == 'Windows' + - name: Install Cygwin uses: egor-tensin/setup-cygwin@master with: @@ -55,4 +59,21 @@ jobs: platform: '${{ matrix.platform }}' cygwin: '${{ matrix.cygwin }}' - # I'm not really sure as to how to properly verify that it worked :-( + - name: Build foo.exe + run: | + $flags = @() + if ('${{ matrix.platform }}' -eq 'x86') { + $flags += '-m32' + } + $flags += @( + '-x', 'c++', + '-std=c++14', + '-o', 'foo', + 'foo.cpp', + '-lstdc++' + ) + if ('${{ runner.os }}' -eq 'Linux') { + $flags += '-lpthread' + } + & g++ $flags + & (Join-Path . foo) @@ -0,0 +1,39 @@ +#include <array> +#include <cstddef> +#include <exception> +#include <functional> +#include <iostream> +#include <mutex> +#include <thread> + +namespace { + +struct Counter { + std::mutex mtx; + std::size_t impl = 0; +}; + +void do_something(Counter& counter) { + std::lock_guard<std::mutex> lck{counter.mtx}; + ++counter.impl; + std::cout << "Doing something #" << counter.impl << '\n'; +} + +} + +int main() { + try { + Counter counter; + std::array<std::thread, 3> 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; +} |