Checkpoint synchronization: Difference between revisions

→‎{{header|Go}}: serialized output
(→‎{{header|Go}}: serialized output)
Line 345:
 
import (
"fmtlog"
"os"
"rand"
"sync"
Line 353 ⟶ 354:
const nMech = 5
const detailsPerMech = 4
 
var l = log.New(os.Stdout, "", 0)
 
func main() {
Line 368 ⟶ 371:
complete.Wait()
// checkpoint reached
fmtl.Println("mechanism", i, "completed")
}
}
Line 387 ⟶ 390:
dword = "detail"
}
fmtl.Println("worker", id, "contracted to assemble", contract, dword)
go worker(a, c, contract, id)
nDetails -= contract
Line 396 ⟶ 399:
// some random time it takes for this worker to assemble a detail
assemblyTime := 5e8 + rand.Int63n(5e8)
fmtl.Println("worker", id, "enters shop")
for i := 0; i < contract; i++ {
<-a
fmtl.Println("worker", id, "assembling")
time.Sleep(assemblyTime)
fmtl.Println("worker", id, "completed detail")
c.Done()
}
fmtl.Println("worker", id, "leaves shop")
}</lang>
Output:
1,707

edits