package main
import (
"fmt"
"sync"
"time"
)
type value struct {
mu sync.Mutex
v int
}
var wg sync.WaitGroup
func print(i, j *value) {
defer wg.Done()
i.mu.Lock()
defer i.mu.Unlock()
time.Sleep(2 * time.Second)
j.mu.Lock()
defer j.mu.Unlock()
fmt.Print(i.v + j.v)
}
func main() {
a := &value{v: 1}
b := &value{v: 2}
var wg sync.WaitGroup
wg.Add(2)
go print(a, b)
go print(b, a)
wg.Wait()
fmt.Println("reached here?")
}
Are they meeting coffman conditions:
So the answer is yes.
todo
A greedy process might take more time required. But having too many memory access sync could degrade performance, on the other hand a larger critical section could lead to starvation.
Site design and logo and content © fossix.org