Skip to content

Commit

Permalink
Merge #697
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bors[bot] and AidanGoldfarb authored May 19, 2021
2 parents 3e83987 + 64d8763 commit cde4439
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions crossbeam-channel/benchmarks/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,21 @@ func select_both(cap int) {
var c3 = make(chan Message, cap)
var done = make(chan bool)

var producer = func(c chan Message) {
var producer = func(c0 chan Message, c1 chan Message, c2 chan Message, c3 chan Message) {
for i := 0; i < MESSAGES / THREADS; i++ {
c <- Message(i)
select {
case c0 <- Message(i):
case c1 <- Message(i):
case c2 <- Message(i):
case c3 <- Message(i):
}
}
done <- true
}
go producer(c0)
go producer(c1)
go producer(c2)
go producer(c3)
go producer(c0,c1,c2,c3)
go producer(c0,c1,c2,c3)
go producer(c0,c1,c2,c3)
go producer(c0,c1,c2,c3)

for t := 0; t < THREADS; t++ {
go func() {
Expand Down

0 comments on commit cde4439

Please sign in to comment.