Files
netstack/tmutex/tmutex_test.go
impact-eintr af8c2fbd42 base package
2022-11-21 14:55:24 +08:00

48 lines
472 B
Go

package tmutex
import (
"fmt"
"runtime"
"testing"
"time"
)
func TestBasicLock(t *testing.T) {
var race = 0
var m Mutex
m.Init()
m.Lock()
go func(){
m.Lock()
race++
m.Unlock()
}()
go func(){
m.Lock()
race++
m.Unlock()
}()
runtime.Gosched() // 让渡cpu
race++
m.Unlock()
time.Sleep(time.Second)
}
func TestShutOut(t *testing.T) {
a := 1
if a < 3 || func() bool {
fmt.Println("ShutOut")
return false
}() {
t.Logf("Ok\n")
}
}