MCPcopy Create free account
hub / github.com/andreiavrammsd/cpp-channel / semaphore

Class semaphore

examples/semaphore.cpp:10–22  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include <vector>
9
10class semaphore {
11 public:
12 explicit semaphore(std::size_t limit) : chan_{limit} {}
13
14 void acquire() { chan_ << empty_; }
15
16 void release() { chan_ >> empty_; }
17
18 private:
19 struct empty {};
20 msd::channel<empty> chan_;
21 empty empty_{}; // See EBO starting C++20: https://en.cppreference.com/w/cpp/language/ebo.html
22};
23
24int simulate_heavy_computation(const int value)
25{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected