Go

Channels

Channels, buffered vs unbuffered, close, select, range over channels, nil channels

22 면접 질문·
Junior
1

What is a channel in Go?

답변

A channel is a data type that enables communication and synchronization between goroutines. It acts as a typed conduit allowing sending and receiving values in a thread-safe manner. Use channels to share data between goroutines instead of sharing memory directly.

2

How to create an unbuffered channel of integers in Go?

답변

An unbuffered channel is created with make(chan T) without specifying capacity. It blocks the sender until a receiver is ready, ensuring strict synchronization. Use unbuffered channels for one-to-one communications requiring explicit synchronization.

3

What is the main difference between a buffered and an unbuffered channel?

답변

An unbuffered channel blocks the sender until a receiver is ready (strict synchronization), while a buffered channel can store values up to its capacity before blocking. Buffered channels decouple goroutines and improve performance in some cases, but can hide concurrency issues. Use unbuffered for synchronization, buffered for throughput.

4

How to create a buffered channel with a capacity of 10 elements?

5

How to send a value into a channel?

+19 면접 질문

다음 면접을 위해 Go을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기