sync/channels: fix bug that caused 100% CPU on block (#6357)

pull/6359/head
Uwe Krüger 2020-09-13 15:13:06 +02:00 committed by GitHub
parent fc88f43e50
commit 168daebccf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -18,7 +18,7 @@ nobj .... number of objects to pass thru the channel
10000000 Objects transfered, results in Objects/µs 10000000 Objects transfered, results in Objects/µs
| nsend | nrec | buflen | **V (gcc -O2)** | **V (clang)** | **V (tcc)** | **Go (glang)** | **Go (gccgo -O2)** | | nsend | nrec | buflen | **V (gcc -O2)** | **V (clang)** | **V (tcc)** | **Go (golang)** | **Go (gccgo -O2)** |
| :---: | :---:| :---: | :---: | :---: | :---: | :---: | :---: | | :---: | :---:| :---: | :---: | :---: | :---: | :---: | :---: |
| 1 | 1 | 0 | 1.97 | 1.63 | 2.08 | 4.65 | 0.56 | | 1 | 1 | 0 | 1.97 | 1.63 | 2.08 | 4.65 | 0.56 |
| 1 | 1 | 100 | 3.05 | 2.29 | 1.93 | 18.90 | 6.08 | | 1 | 1 | 100 | 3.05 | 2.29 | 1.93 | 18.90 | 6.08 |
@ -38,7 +38,7 @@ nobj .... number of objects to pass thru the channel
10000000 Objects transfered, results in Objects/µs 10000000 Objects transfered, results in Objects/µs
| nsend | nrec | buflen | **V (gcc -O2)** | **Go (glang)** | | nsend | nrec | buflen | **V (gcc -O2)** | **Go (golang)** |
| :---: | :---:| :---: | :---: | :---: | | :---: | :---:| :---: | :---: | :---: |
| 1 | 1 | 0 | 0.37 | 0.21 | | 1 | 1 | 0 | 0.37 | 0.21 |
| 1 | 1 | 100 | 1.03 | 0.74 | | 1 | 1 | 100 | 1.03 | 0.74 |

View File

@ -110,7 +110,7 @@ pub fn new_channel<T>(n u32) &Channel {
fn new_channel_st(n u32, st u32) &Channel { fn new_channel_st(n u32, st u32) &Channel {
return &Channel{ return &Channel{
writesem: new_semaphore_init(if n > 0 { n + 1 } else { 1 }) writesem: new_semaphore_init(if n > 0 { n } else { 1 })
readsem: new_semaphore_init(if n > 0 { u32(0) } else { 1 }) readsem: new_semaphore_init(if n > 0 { u32(0) } else { 1 })
writesem_im: new_semaphore() writesem_im: new_semaphore()
readsem_im: new_semaphore() readsem_im: new_semaphore()