Zum Hauptinhalt springen
•
Sichere ProgrammierungThe Jevons Paradox of Judgment(03.10.2026 um 03:12 Uhr)
•
Sichere ProgrammierungI built a game so my family could see who always gets skipped(03.10.2026 um 03:13 Uhr)
••••
Sichere ProgrammierungTrack which companies are hiring (and closing roles) with a jobs API(03.10.2026 um 03:16 Uhr)
•
Sichere ProgrammierungAI Coding Has Made Project-Switching Way Too Easy(03.10.2026 um 03:16 Uhr)
••••
Sichere ProgrammierungThe Jevons Paradox of Judgment(03.10.2026 um 03:12 Uhr)
•
Sichere ProgrammierungI built a game so my family could see who always gets skipped(03.10.2026 um 03:13 Uhr)
••••
Sichere ProgrammierungTrack which companies are hiring (and closing roles) with a jobs API(03.10.2026 um 03:16 Uhr)
•
Sichere ProgrammierungAI Coding Has Made Project-Switching Way Too Easy(03.10.2026 um 03:16 Uhr)
•••
Intelligence View
⚡ tsecurity.de Intelligence

[Golang] Understanding Unbuffered and Buffered Channels

Table of contents Channel capacity Behavior Closed channel Receive-Only & Send-only Channel References Channel capacity Unbuffered channel: Has no capacity.…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!




Table of contents




  • Channel capacity

  • Behavior

  • Closed channel

  • Receive-Only & Send-only Channel

  • References






Channel capacity




  • Unbuffered channel:


    • Has no capacity.

    • You can imagine it like a highway that allows one car to run throungh but does not support any cars to park there.






  • Buffered channel:


    • Has a fixed capacity at declaration time.

    • It's like a queue that supports holding up to a fixed number of pending messages before consuming.











Behavior





  • Unbuffered channel:




    • Sender is blocked until a receiver receive the message.

    • Receiver is blocked until a sender sends a message.

    • The sending and receiving processes are synchronous.








  • Buffered channel:




    • Senders are blocked only when the buffer is full.

    • Receivers are blocked when the buffer is empty.

    • The sending and receiving processes are asynchronous. Senders are released immediately after the sending action without waiting for the receiver.








Worth noting: An unbuffered channel differs from a buffered channel with a size of 1 according to the behavior described above.






Closed channel



When a channel is closed in Go using the close() function:





  • Sending to a closed channel causes a panic.


  • Receiving from a closed channel continues to retrieve values until the buffer is drained (for buffered channels).
    After the buffer is empty, further receives return the zero value of the channel's type and do not block.



You can check if a channel is closed by receiving a second value from the channel, e.g., v, ok := <-ch. The ok will be false if the channel is closed.






Receive-Only & Send-only Channel



Receive-only channel in Go is a channel that can only be used to receive values.





  • Declaration: var ch <-chan int defines a channel from which only receiving is allowed.


  • Behavior:


    • Attempting to send to a read-only channel will result in a compilation error.

    • Attempting to pass a receive-only channel into a function that requires normal channel also lead to a compilation error.








Send-only channel is similar.




var ch chan<- int









References



🔍 CTI & Forensik

Cyber Threat Intelligence & Forensik

ATT&CK-Navigator · IoC-Radar · Exploit-Belege
CTI Threat Relationship Graph
Akteure · Techniken · Beziehungen
2 Knoten · 1 Relationen
CVE / Incident Threat Actor Software MITRE ATT&CK CWE Weakness IoC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten [Golang] Understanding Unbuffered and Buffered Channels

Thematisch verwandte Begriffe: Golang, Understanding, Unbuffered, Buffered · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag