Junior — Middle
Kas saaksite selgitada, mida mõistetakse terminiga 'Sheduler' tarkvara kontekstis?
sobes.tech AI
Vastus AI-lt
In software, the term "Scheduler" typically refers to a component responsible for managing the order and timing of task or process execution. In the context of Golang, it can be a system that distributes goroutines (lightweight threads) for execution, deciding when and which goroutine to start.
For example, Go's built-in scheduler manages switching between goroutines, ensuring concurrent execution without the need to manually manage operating system threads.
An example of a simple task scheduler in Go:
package main
import (
"fmt"
"time"
)
func task(name string) {
fmt.Println("Start task", name)
time.Sleep(1 * time.Second)
fmt.Println("End task", name)
}
func main() {
go task("A")
go task("B")
time.Sleep(2 * time.Second) // Wait for goroutines to finish
}
Here, the Go scheduler manages the execution of two goroutines in parallel.