Skip to content
Ta180m  /   Idiot-Code-Golf  /   Discussions #9  /  
  • Unwatch 1

    Notifications

    Get push notifications on iOS or Android.
  • Fork 0

Problem 8: Create Go channels… without Go channels #9

Unanswered
mpldr asked this question in Q&A
Problem 8: Create Go channels… without Go channels #9
on Apr 27, 2021 · 3 answers · 1 reply

This one is a bit different:
We want a channel implementation at least similar to channels in Go. Unbuffered channels to be more precise.

A short rundown:

  • a channel can "transport" any type
  • a channel write is blocking until the value is consumed
  • similarly a read is blocking until a value is received
  • channels can be reused

The solution being stable, secure, or sensible is not part of the problem.

Replies

3 suggested answers
·
1 reply

mpldr
on Apr 27, 2021
Collaborator Author

I fear this one might actually be useful… but hey, even a blind hen sometimes finds a grain of corn.

0 replies
@Ta180m

mpldr
on Apr 27, 2021
Collaborator Author

https://github.com/Ta180m/Idiot-Code-Golf/blob/main/channels/bashnels.sh

Is it tested? only for the most basic of use-cases.
Is it working? surprisingly: yes
Is it stable? depends on your definition of stable.

0 replies
@Ta180m

Ta180m
on Apr 27, 2021
Maintainer

https://github.com/Ta180m/Idiot-Code-Golf/blob/main/channels/channels.cpp

A "modern C++" solution by hacking together some C++ 17 and C++ 20 features such as std::any, auto, and concepts. std::any in particular feels like such a crazy hack of a language that has deviated so much from C by trying to do everything possible. Obviously, this a naïve implementation that should not be used if you're actually working with concurrency. Among the many flaws, reads will consume 100% CPU in the while loop until it receives a value.

1 reply
@mpldr

mpldr on Apr 28, 2021
Collaborator Author

reads will consume 100% CPU in the while loop

That's just a free bonus :D

I haven't tried it yet, but does it block on write? because then it should not be able to run… or better: finish

@Ta180m
Select a reply ctrl .
Remember, contributions to this repository should follow our GitHub Community Guidelines.
Category
Change category
Q&A
Labels
None yet
2 participants
  • Lock conversation

    Lock conversation on this discussion

    • Other users can’t add new comments to this discussion.
    • You and other collaborators with access to this repository can still leave comments that others can see.
    • You can always unlock this discussion again in the future.
  • Transfer discussion
  • Pin discussion
    Loading...
  • Create issue from discussion
  • Delete discussion?

    The discussion will be deleted permanently. You will not be able to restore the discussion or its comments

Loading complete