Request for more functionality for channels

Aperta
#288 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
api, backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
C++
Stelle
351
Fork
47
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di boostorg/cobalt

Tutte le issue di boostorg/cobalt

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.