Created
December 17, 2018 13:01
-
-
Save pschlump/c579a533ad15efd2126e434b98d2b937 to your computer and use it in GitHub Desktop.
Possible problem with our implementation of Phase 14.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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