Changeset 160ee4c
- Timestamp:
- May 3, 2022, 12:52:24 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- db89655
- Parents:
- f56101f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/readyQ/churn.go
rf56101f r160ee4c 2 2 3 3 import ( 4 "context"5 4 "flag" 6 5 "fmt" 7 6 "math/rand" 7 "runtime" 8 8 "sync" 9 9 "sync/atomic" 10 10 "time" 11 "golang.org/x/sync/semaphore"12 11 "golang.org/x/text/language" 13 12 "golang.org/x/text/message" 14 13 ) 15 14 16 func churner(result chan uint64, start *sync.WaitGroup, skip bool, spots [] * semaphore.Weighted) { 17 ctx := context.TODO() 15 func churner(result chan uint64, start *sync.WaitGroup, spots [] chan struct {}) { 18 16 s := rand.NewSource(time.Now().UnixNano()) 19 17 rng := rand.New(s) … … 24 22 25 23 sem := spots[ rng.Intn(100) % len(spots) ]; 26 if !skip { sem.Release(1); }; 27 sem.Acquire(ctx,1); 28 skip = false; 24 sem <- (struct {}{}) 25 <- sem; 29 26 30 27 count += 1 … … 52 49 wg.Add(1) 53 50 54 spots := make([] * semaphore.Weighted, spot_cnt)51 spots := make([] chan struct {}, spot_cnt) 55 52 for i := range spots { 56 ctx := context.TODO() 57 spots[i] = semaphore.NewWeighted(20000) 58 spots[i].Acquire(ctx, 20000) 53 spots[i] = make(chan struct {}, 1) 59 54 } 60 55 61 56 for i := 0; i < nthreads; i++ { 62 go churner(result, &wg, i < len(spots),spots)57 go churner(result, &wg, spots) 63 58 } 64 59 fmt.Printf("Starting\n"); … … 74 69 fmt.Printf("\nDone\n") 75 70 76 for i := range spots { 77 spots[i].Release(10000) 71 for atomic.LoadInt64(&threads_left) != 0 { 72 for i := range spots { 73 select { 74 case spots[i] <- (struct {}{}): 75 default: 76 } 77 runtime.Gosched() 78 } 78 79 } 79 80
Note: See TracChangeset
for help on using the changeset viewer.