How are golang selection instructions executed?

In particular, I have some blocking queues in C ++, and I want to wait until some of them have some element that I can put.

The only mechanism I can think of is to create a separate thread for each queue that appears from the input queue and transfers to the main queue that the original thread can wait for.

It seems that the resource is heavy in order to spawn N new threads and then kill them every time I want to appear from the queue group.

Does Golang provide an even more elegant mechanism that I could implement in my own C ++ code?

+4
source share
2 answers

, Go select , , - .

  • select , .
  • , ,
  • ,
  • / , ,
    • sudog, goroutine ( goroutine sudog), goroutine
    • gopark, ,
    • , , select goroutine

, , , , . - Go select , chan.

, , . select , , , , , , , -------- .

+4

Golang select C select (. GNU libc ), I/O . , .

-1

All Articles