gitlab.com/Raven-IO/raven-delve@v1.22.4/_fixtures/databpcountstest.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"math/rand"
     6  	"sync"
     7  	"time"
     8  )
     9  
    10  var globalvar1 int
    11  
    12  func demo(id int, wait *sync.WaitGroup) {
    13  	for i := 0; i < 100; i++ {
    14  		sleep := rand.Intn(10) + 1
    15  		fmt.Printf("id: %d step: %d sleeping %d\n", id, i, sleep)
    16  		globalvar1 = globalvar1 + 1
    17  		time.Sleep(time.Duration(sleep) * time.Millisecond)
    18  	}
    19  
    20  	wait.Done()
    21  }
    22  
    23  func main() {
    24  	wait := new(sync.WaitGroup)
    25  	wait.Add(1)
    26  	wait.Add(1)
    27  	go demo(1, wait)
    28  	go demo(2, wait)
    29  
    30  	wait.Wait()
    31  }