Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "time"
- )
- func main() {
- i := 0
- c1 := make(chan int, 1)
- c2 := make(chan int, 1)
- for {
- for j := 0; j < 5; j++ {
- if j != i && j != i+2 {
- println(j, "is thinking")
- }
- }
- go philosopher(i, c1)
- go philosopher(i+2, c2)
- <-c1
- <-c2
- i++
- i = i % 5
- }
- }
- func philosopher(id int, out chan<- int) {
- println(id, "is eating")
- time.Sleep(time.Millisecond * 1000)
- out <- 1
- }
Add Comment
Please, Sign In to add comment