2020-08-14 22:18:42 +03:00
|
|
|
const (
|
|
|
|
num_iterations = 10000
|
|
|
|
)
|
|
|
|
|
|
|
|
struct St {
|
|
|
|
mut:
|
2020-08-17 00:01:49 +03:00
|
|
|
dummy i64
|
|
|
|
dummy2 u32
|
|
|
|
dummy3 i64
|
|
|
|
n int
|
|
|
|
dummy4 int
|
2020-08-14 22:18:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// this function gets an array of channels for `St` references
|
|
|
|
fn do_rec_calc_send(chs []chan mut St) {
|
|
|
|
for {
|
2021-05-08 13:32:29 +03:00
|
|
|
mut s := <-chs[0] or { break }
|
2020-08-14 22:18:42 +03:00
|
|
|
s.n++
|
2020-08-23 03:12:05 +03:00
|
|
|
chs[1] <- s
|
2020-08-14 22:18:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_channel_array_mut() {
|
|
|
|
mut chs := [chan mut St{cap: 1}, chan mut St{}]
|
2022-11-05 10:46:40 +03:00
|
|
|
spawn do_rec_calc_send(chs)
|
2020-08-17 00:01:49 +03:00
|
|
|
mut t := &St{
|
2020-08-14 22:18:42 +03:00
|
|
|
n: 100
|
|
|
|
}
|
|
|
|
for _ in 0 .. num_iterations {
|
2020-08-23 03:12:05 +03:00
|
|
|
chs[0] <- t
|
|
|
|
t = <-chs[1]
|
2020-08-14 22:18:42 +03:00
|
|
|
}
|
2020-09-05 02:36:20 +03:00
|
|
|
chs[0].close()
|
2020-08-14 22:18:42 +03:00
|
|
|
assert t.n == 100 + num_iterations
|
|
|
|
}
|