轻松实现Rust系统入门,实战编译器开发

download:轻松实现Rust系统入门,实战编译器开发 `package main
【轻松实现Rust系统入门,实战编译器开发】import (
"fmt"
"sync"
"time"
)
func ReadDB(wg sync.WaitGroup, Chsignsl chan int, rm sync.RWMutex) {
Chsignsl <- 123
rm.RLock()
fmt.Println("reading database....")
<-time.After(1)
rm.RUnlock()
<-Chsignsl
wg.Done()
}
func WriteDB(wg sync.WaitGroup, Chsignsl chan int, rm sync.RWMutex) {
Chsignsl <- 123
rm.Lock()
fmt.Println("writting database....")
timer := time.NewTicker(time.Second)
for i := 0; i < 1; i++ {
<-timer.C
}
rm.Unlock()
<-Chsignsl
wg.Done()
}
func main() {
var wg sync.WaitGroup
var rmt sync.RWMutex
Chsignsl := make(chan int, 5)
for i := 0; i < 10; i++ {

for i := 0; i < 3; i++ { wg.Add(1) go ReadDB(&wg, Chsignsl, &rmt) } wg.Add(1) go WriteDB(&wg, Chsignsl, &rmt)

}
wg.Wait()
fmt.Println("主协程完毕...")
}

    推荐阅读