Skip to content

Instantly share code, notes, and snippets.

@kaneshin
Created April 25, 2018 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaneshin/79b0b80286ec135cc00330874875139b to your computer and use it in GitHub Desktop.
Save kaneshin/79b0b80286ec135cc00330874875139b to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"regexp"
"sync"
)
var re1 = regexp.MustCompile("hoge.*")
var re2 = regexp.MustCompile("foo.*")
func main() {
v := map[int]int{}
var wg sync.WaitGroup
var mu sync.RWMutex
for i := 0; i < 100; i++ {
i := i
wg.Add(1)
go func() {
defer wg.Done()
for k := 0; k < 1000; k++ {
j := i * k
mu.Lock()
v[j] = k
mu.Unlock()
}
}()
}
wg.Wait()
for _, vv := range v {
fmt.Println(vv)
}
go func() {
re10 := re1.Copy()
re10.FindString()
}()
go func() {
re11 := re1.Copy()
re11.FindString()
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment