any order of which the select statements are evaluated?
151 views
Skip to first unread message
ated...@gmail.com
unread,
Oct 12, 2015, 8:45:38 AM10/12/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
Is there an order to the select statements are evaluated?
Given this example:
for { select { case inc := <-incoming: // process incoming data case out := <-outgoing: // send out outgoing data case <-done: // done } }
Say incoming and outgoing channels are buffered and always crowded, is it possible that the 'done' channel will never get invoked because the loop always takes `incoming` first, then `outgoing` second, and then after that `done` if nothing is incoming and outgoing?
Jan Mercl
unread,
Oct 12, 2015, 8:49:17 AM10/12/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
> Is there an order to the select statements are evaluated?
"""
For all the cases in the statement, the channel operands of receive operations and the channel and right-hand-side expressions of send statements are evaluated exactly once, *in source order* ... """ Src: https://golang.org/ref/spec#Select_statements
--
-j
Roberto Zanotto
unread,
Oct 12, 2015, 9:05:08 AM10/12/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
Your first question is about evaluation order (which is technically what Jan answered), but your last question is if it's possible for some channels to starve. Short answer: no. If multiple channels can proceed, a pseudo-random choice is made. Chances of starvation are reeeeeeealy low. Read the whole paragraph about the select statement in the spec ;)