# The Nature Of Channels In Go

DevFeed: [The Nature Of Channels In Go](<https://devfeed.tech/articles/the-nature-of-channels-in-go-22096.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2014/02/the-nature-of-channels-in-go.html>)

Published: 2014-02-17T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Concurrent Programming](<https://devfeed.tech/topics/concurrent-programming.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [capacity](<https://devfeed.tech/tags/capacity.md>), [channel](<https://devfeed.tech/tags/channel.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [goroutines](<https://devfeed.tech/tags/goroutines.md>), [programming](<https://devfeed.tech/tags/programming.md>), [state](<https://devfeed.tech/tags/state.md>), [synchronization](<https://devfeed.tech/tags/synchronization.md>)

## AI overview

This tutorial explains Go channels as type-safe message queues that synchronize goroutines exchanging resources. It distinguishes unbuffered channels, which require both sender and receiver to be ready, from buffered channels, whose capacity affects when sends and receives block.

## Source excerpt

Introduction In my last post called Concurrency, Goroutines and GOMAXPROCS, I set the stage for talking about channels. We discussed what concurrency was and how goroutines played a role. With that foundation in hand, we can now understand the nature of channels and how they can be used to synchronize goroutines to share resources in a safe, less error prone and fun way. What Are Channels Channels are type safe message queues that have the intelligence to control the behavior of any goroutine attempting to receive or send on it. A channel acts as a conduit between two goroutines and will synchronize the exchange of any resource that is passed through it. It is the channel's ability to control the goroutines interaction that creates the synchronization mechanism. When a channel is created with no capacity, it is called an unbuffered channel. In turn, a channel created with capacity is called a buffered channel. To understand what the synchronization behavior will be for any goroutine interacting with a channel, we need to know the type and state of the channel. The scenarios are a bit different depending on whether we are using an unbuffered or buffered channel, so let's talk about each one independently. Unbuffered Channels Unbuffered channels have no capacity and therefore require both goroutines to be ready to make any exchange. When a goroutine attempts to send a resource to an unbuffered channel and there is no goroutine waiting to receive the resource, the channel will lock the sending goroutine and make it wait. When a goroutine attempts to receive from an unbuffered channel, and there is no goroutine waiting to send a resource, the channel will lock the receiving goroutine and make it wait. View linked image: Screen Shot