base package

This commit is contained in:
impact-eintr
2022-11-21 14:55:24 +08:00
parent c16f1d0e8c
commit af8c2fbd42
11 changed files with 1296 additions and 1 deletions

47
tmutex/tmutex_test.go Normal file
View File

@@ -0,0 +1,47 @@
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")
}
}