Junior — Middle
What are shared streams used for in programming?
sobes.tech AI
Answer from AI
Shared goroutines in Go are designed to execute multiple functions or tasks concurrently, allowing efficient utilization of multi-processor systems and improving program performance.
Main goals of shared goroutines:
- Parallel execution of code to increase processing speed.
- Asynchronous execution of tasks to avoid blocking the main thread.
- Organizing concurrent access to resources using channels and other synchronization mechanisms.
Example of starting a goroutine:
func sayHello() {
fmt.Println("Hello from goroutine")
}
func main() {
go sayHello() // start function in a separate goroutine
time.Sleep(time.Second) // wait for the goroutine to complete
}