Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
think of channels as queues. unbuffered - with length 1, buffered - with length n (ch := make(chan struct{}, n). Writing to the channel can be done if there are still places in the channel, when the channel is full, the recording is locked (i.e. code " gets up" on this attempt and waits for a seat to become available). according to this:
ch1 := make(chan struct{})
ch1 <- struct{}{} //ок, ушло в канал
ch1 <- struct{}{} //висим и ждем когда кто-нить прочитает из канала
ch2 := make(chan struct{},3)
ch2 <- struct{}{} //ок, ушло в канал
ch2 <- struct{}{} //также ушло
ch2 <- struct{}{} //и еще ушло
ch2 <- struct{}{} //а вот тут лок. висим и ждем когда кто-то прочитает из канала
In an unbuffered channel, the sender can determine whether a message has been received. Sometimes this is important, for example, for synchronization instead of semaphores, although it does not guarantee that the recipient will be able to process it, and not immediately fall.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question