We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
You can continue the conversation there. Go to discussion →
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
需求:
可参考的:
package lockedfile_sp import ( "fmt" "sync" "testing" "time" "github.com/rogpeppe/go-internal/lockedfile" ) func TestLockedfileMutex(t *testing.T) { begin := time.Now() fmt.Println("start") mutex := lockedfile.MutexAt("/tmp/hello") wg := sync.WaitGroup{} wg.Add(2) go func() { defer wg.Done() unlock, err := mutex.Lock() if err != nil { panic(err) } defer unlock() fmt.Println("a", time.Since(begin)) time.Sleep(time.Second * 3) }() go func() { defer wg.Done() unlock, err := mutex.Lock() if err != nil { panic(err) } defer unlock() fmt.Println("b", time.Since(begin)) time.Sleep(time.Second * 3) }() wg.Wait() fmt.Println("end", time.Since(begin)) }
单进程执行:
start a 267.708µs b 3.001576625s end 6.002901375s
多进程执行:
start b 79.042µs a 3.001326792s end 6.002688917s start b 5.688241458s a 8.689420375s end 11.690721417s
The text was updated successfully, but these errors were encountered:
No branches or pull requests
需求:
可参考的:
单进程执行:
多进程执行:
The text was updated successfully, but these errors were encountered: