From 65714e30cbfa1af1bc561f7f32224381722f032e Mon Sep 17 00:00:00 2001 From: Anh Tuan Le Date: Sun, 31 Aug 2025 20:40:31 +0700 Subject: [PATCH] feat(playground): add initial main.go with goroutine example - Implement a simple Go application that prints "Hello, World!" - Introduce a goroutine that demonstrates a potential goroutine leak and race condition - Include a sleep mechanism to illustrate concurrent execution --- cmd/playground/main.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 cmd/playground/main.go diff --git a/cmd/playground/main.go b/cmd/playground/main.go new file mode 100644 index 0000000..8cecad2 --- /dev/null +++ b/cmd/playground/main.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" + "time" +) + +func main() { + fmt.Println("Hello, World!") + + // A goroutine which cause goroutine leak + // this goroutines should cause race condition + message := "Hello, World!" + go func(s string) { + time.Sleep(10 * time.Second) + fmt.Println(s) + }(message) + + time.Sleep(1 * time.Second) + fmt.Println(message) +}