On Thu, Nov 12, 2020 at 6:19 PM 陶青云 <qingyu...@gmail.com> wrote:

> ```
> // c  is buffered channel
> select {
> case c <- result:
> default:
>      // full, drop old one
>       <-c
>       c <- result
>  }
> ```
>
> I have a code like this,  but there may be a race condition in the default
> case. I enconter a
> deadlock that the goroutine block on  'c<'.
>

In addition to what Ian said you should note that a buffered channel is
essentially a FIFO queue. The equivalent code that operates on a queue in
any other language (e.g., Python) will have the same race. What you're
asking for is something like the behavior provided by an API such as
Python's collections.deque
<https://docs.python.org/2/library/collections.html#collections.deque>.
Whether any of the solutions you might find by searching for something like
"golang deque" satisfy your requirements can't be answered given the
information you have provided.

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD_0x7D4UJnBx7jMD-rnuniVoi46OnZgBQVDP9JZKnOHyA%40mail.gmail.com.

Reply via email to