Request for more functionality for channels
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 45/100
Research direction
Read the channel implementation and its tests to find where move operations, capacity, and void channel reads and writes are defined. Start by checking which requested behaviors are supported by the current API and how channel operations handle capacity. Done means agreeing on and implementing the desired set of channel features, with tests covering the selected behaviors.
Written by the indexing model from the issue text.
Description
Moving
Channels are currently having their move constructor and operator explicitly deleted. This prevents a lot of sorts of code decomposition since it is not even possible to make a function to abstract some channels-related stuff. Not to mention that it forces library users into writing some really poor code (for example wrapping channel into unique_ptr to enable moving)
struct smth {
...
boost::cobalt::channel<void> chan;
};
// all below is basically impossible
auto transfer_ownership(smth smth);
boost::cobalt::promise<smth> async_initialization(...);
Occupied capacity requests
Now it is impossible to reason about how much elements is inside the channel. This makes writing a channel-based condition_variable pretty much impossible. There also may be other cases for occupied capacity introspection. This one is just what I have stuck with. Overall, this shall not be a problem to add one extra getter into channel
read/write(N) overload for void channel
Void channel is basically a semaphore. And sometimes it is useful to state that some operations on such semaphore require more parallelism units than others. In such cases something like that has to be written
// for acquiring of N slots
for (size_t i = 0; i < N; ++i) {
co_await chan.read();
}
// for releasing of N slots
for (size_t i = 0; i < N; ++i) {
co_await chan.write();
}
There is also a problem that in both of these examples a deadlock is possible if channel has less slots capacity in it than N. And another smaller problem is that if read/write blocks then another one extra slot (up to N) is asked and is possibly blocked once again making otherwise unnecessary context switches in scheduler.
Both of abovementioned problems are avoidable (except for context switches) if user constructs it's own primitive for semaphore using channel. But semaphore is probably needed often enough in different codebases for library to provide it
Batch-processing for data in non-void channels may also be useful in theory. But I cannot imagine a good example for this and thus will not advocate for it
- Dominant language
- C++
- Stars
- 351
- Forks
- 47
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/cobalt
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
Similar issues
-
agent:WSL code-review linux pri:medium refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
kind/enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
psi29a/d2decomped#691 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
CachyOS/packageinstaller#144 ·
Maintainers usually reply within 1 day
-
(S1 - Need confirmation)
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
CleverRaven/Cataclysm-DDA#89715 ·
Maintainers usually reply within 1 day