Skip to content

karsasdev/nested-goroutines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demonstrates recursive goroutine spawning in Go, forming a depth-limited concurrent tree.

Configuration

  • Root goroutines: 3 (root-0, root-1, root-2)
  • Children per node: 3
  • Maximum depth: 3

Goroutine Tree

3 Roots (root-0, root-1, root-2)
  │
  ├─→ Each spawns 3 children = 9 total at Depth 1
  │     │
  │     ├─→ Each spawns 3 children = 27 total at Depth 2
  │     │     │
  │     │     ├─→ Each spawns 3 children = 81 total at Depth 3
  │     │     │     │
  │     │     │     └─→ 81 Leaf nodes (no further spawning)

Tree:

  • 3 roots (root-0, root-1, root-2) - each follows the same branching pattern
  • 9 goroutines spawned at depth 1 (3 roots × 3 children each)
  • 27 goroutines spawned at depth 2 (9 parents × 3 children each)
  • 81 goroutines spawned at depth 3 (27 parents × 3 children each)
  • 81 leaf nodes at depth 3 (these don't spawn any children)

So Total = 9 + 27 + 81 = 117 goroutines spawned

How to run

go run main.go

The program will show each goroutine starting, spawning children, and completing. At the end, it displays the total number of goroutines spawned.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages