新增工具库

This commit is contained in:
boyce
2019-02-28 09:25:13 +08:00
parent a831db0a4e
commit d021127a77
5 changed files with 375 additions and 0 deletions

15
util/semaphore.go Normal file
View File

@@ -0,0 +1,15 @@
package util
type Semaphore chan struct{}
func MakeSemaphore(n int) Semaphore {
return make(Semaphore, n)
}
func (s Semaphore) Acquire() {
s <- struct{}{}
}
func (s Semaphore) Release() {
<-s
}