Skip to content

Instantly share code, notes, and snippets.

@pschlump
Created December 17, 2018 13:01
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 pschlump/c579a533ad15efd2126e434b98d2b937 to your computer and use it in GitHub Desktop.
Save pschlump/c579a533ad15efd2126e434b98d2b937 to your computer and use it in GitHub Desktop.
Possible problem with our implementation of Phase 14.
package main
import (
"fmt"
"sync"
"time"
"github.com/pschlump/MiscLib"
"github.com/pschlump/godebug"
)
var aFunc []func()
var bFunc func()
var wg sync.WaitGroup
func createCh() {
ch := make(chan string)
aFunc = append(aFunc, func() {
wg.Add(1)
defer wg.Done()
ch <- "msg"
})
qt := make(chan string)
bFunc = func() {
wg.Add(1)
defer wg.Done()
qt <- "msg"
}
for {
select {
case <-qt:
fmt.Printf("%sSUCCESS%s - quit - At:%s %s\n", MiscLib.ColorGreen, MiscLib.ColorRed, MiscLib.ColorReset, godebug.LF())
return
case s := <-ch:
fmt.Printf("%sGOT%s - %s - At:%s %s\n", MiscLib.ColorGreen, MiscLib.ColorRed, s, MiscLib.ColorReset, godebug.LF())
}
}
}
func main() {
for i := 0; i < 20; i++ {
go func() {
wg.Add(1)
defer wg.Done()
createCh()
}()
time.Sleep(time.Duration(100) * time.Millisecond)
aFunc[i]()
bFunc() // Kill it off
}
fmt.Printf("Ran It, Now wait if function still exists\n")
time.Sleep(time.Duration(100) * time.Millisecond)
aFunc[0]()
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment