Junior — Middle
Can you explain what the term 'stream' means in Unix-like operating systems?
sobes.tech AI
Answer from AI
In Unix-like operating systems, the term "thread" refers to the smallest unit of execution within a process. Threads within the same process share memory and resources, which allows for efficient parallel task execution. For example, one process can contain multiple threads that simultaneously process different parts of data, improving performance and responsiveness of the application.
Example in Go, where multiple threads (goroutines) are created:
package main
import (
"fmt"
"time"
)
func worker(id int) {
fmt.Printf("Worker %d started\n", id)
time.Sleep(time.Second)
fmt.Printf("Worker %d finished\n", id)
}
func main() {
for i := 1; i <= 3; i++ {
go worker(i) // start goroutine
}
time.Sleep(2 * time.Second) // wait for goroutines to finish
}