From 7df4a2af64d6032f74da6af37d327d2037effda8 Mon Sep 17 00:00:00 2001 From: nynicg Date: Fri, 10 May 2019 15:11:04 +0800 Subject: [PATCH] barrier pattern --- concurrency/n_barrier/main.go | 39 ++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/concurrency/n_barrier/main.go b/concurrency/n_barrier/main.go index 984e1f7..45276a2 100644 --- a/concurrency/n_barrier/main.go +++ b/concurrency/n_barrier/main.go @@ -13,27 +13,28 @@ type IBarrier interface { // once type ChanBarrier struct { - gos int - curGos int - ch chan struct{} - m sync.Mutex + waitCh chan struct{} + sign chan struct{} } func NewChanBarrier(gos int)*ChanBarrier{ - return &ChanBarrier{ - gos:gos, - ch:make(chan struct{}), + b := &ChanBarrier{ + waitCh:make(chan struct{} ,gos-1), + sign:make(chan struct{}), } + for i:=0;i