mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
sync: don't force Mutex and Semaphore to be reference (#8331)
This commit is contained in:
@@ -9,7 +9,7 @@ fn getint() int {
|
||||
return 8
|
||||
}
|
||||
|
||||
fn f1(ch1 chan int, ch2 chan St, ch3 chan int, ch4 chan int, ch5 chan int, sem sync.Semaphore) {
|
||||
fn f1(ch1 chan int, ch2 chan St, ch3 chan int, ch4 chan int, ch5 chan int, mut sem sync.Semaphore) {
|
||||
mut a := 5
|
||||
select {
|
||||
a = <-ch3 {
|
||||
@@ -40,7 +40,7 @@ fn f1(ch1 chan int, ch2 chan St, ch3 chan int, ch4 chan int, ch5 chan int, sem s
|
||||
sem.post()
|
||||
}
|
||||
|
||||
fn f2(ch1 chan St, ch2 chan int, sem sync.Semaphore) {
|
||||
fn f2(ch1 chan St, ch2 chan int, mut sem sync.Semaphore) {
|
||||
mut r := 23
|
||||
for i in 0 .. 2 {
|
||||
select {
|
||||
@@ -66,7 +66,7 @@ fn test_select_blocks() {
|
||||
ch3 := chan int{}
|
||||
ch4 := chan int{}
|
||||
ch5 := chan int{}
|
||||
sem := sync.new_semaphore()
|
||||
mut sem := sync.new_semaphore()
|
||||
mut r := false
|
||||
t := select {
|
||||
b := <-ch1 {
|
||||
@@ -79,7 +79,7 @@ fn test_select_blocks() {
|
||||
}
|
||||
assert r == true
|
||||
assert t == true
|
||||
go f2(ch2, ch3, sem)
|
||||
go f2(ch2, ch3, mut sem)
|
||||
n := <-ch3
|
||||
assert n == 23
|
||||
ch2 <- St{
|
||||
@@ -87,7 +87,7 @@ fn test_select_blocks() {
|
||||
}
|
||||
sem.wait()
|
||||
stopwatch := time.new_stopwatch({})
|
||||
go f1(ch1, ch2, ch3, ch4, ch5, sem)
|
||||
go f1(ch1, ch2, ch3, ch4, ch5, mut sem)
|
||||
sem.wait()
|
||||
elapsed_ms := f64(stopwatch.elapsed()) / time.millisecond
|
||||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/high-resolution-timers
|
||||
|
||||
Reference in New Issue
Block a user