Skip to content

Commit 8de64d9

Browse files
Merge #697
697: fixed go.go to properly select over channels during the put operation in select_both r=taiki-e a=AidanGoldfarb Per the [crossbeam benchmark configuration](https://github.com/crossbeam-rs/crossbeam/blob/master/crossbeam-channel/benchmarks/README.md) the `select_both` function is defined as: > select_both: T threads send N / T messages each by selecting over T channels. T other threads receive N / T messages each by selecting over the T channels. Previously, the `select_both` function in [go.go](https://github.com/crossbeam-rs/crossbeam/blob/3e83987f258ab85a6573704ba538f2efdfe587c1/crossbeam-channel/benchmarks/go.go#L128) did not utilize the `select` statement while sending messages. Added the use of the select statement. Co-authored-by: Aidan <agoldfa7@u.rochester.edu>
2 parents 3e83987 + 64d8763 commit 8de64d9

File tree

1 file changed

+11
-6
lines changed
  • crossbeam-channel/benchmarks

1 file changed

+11
-6
lines changed

crossbeam-channel/benchmarks/go.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,21 @@ func select_both(cap int) {
136136
var c3 = make(chan Message, cap)
137137
var done = make(chan bool)
138138

139-
var producer = func(c chan Message) {
139+
var producer = func(c0 chan Message, c1 chan Message, c2 chan Message, c3 chan Message) {
140140
for i := 0; i < MESSAGES / THREADS; i++ {
141-
c <- Message(i)
141+
select {
142+
case c0 <- Message(i):
143+
case c1 <- Message(i):
144+
case c2 <- Message(i):
145+
case c3 <- Message(i):
146+
}
142147
}
143148
done <- true
144149
}
145-
go producer(c0)
146-
go producer(c1)
147-
go producer(c2)
148-
go producer(c3)
150+
go producer(c0,c1,c2,c3)
151+
go producer(c0,c1,c2,c3)
152+
go producer(c0,c1,c2,c3)
153+
go producer(c0,c1,c2,c3)
149154

150155
for t := 0; t < THREADS; t++ {
151156
go func() {

0 commit comments

Comments
 (0)