I wanted to learn (at least try) some new language, because I have feeling that I haven’t learnt anything in a long time. So I catched hype wave around Go. It is statically typed, with garbage collector, without OOP (I don’t like it anyway), by default statically linked language that was invented in Google. There is really nice and short tour that guided me in the beginings. Go’s killer feature is it’s concurrency model. It uses so called goroutines that are more lightweight than threads and channels that take care of communication between goroutines.

I wanted to try this features, how easy I can understand and work with it so I decided to implement Sleeping Barber Problem. I already implemented it few years ago in C using semaphores. The work with Go was great, although it is a little different from mainstream programming languages. It was much easier than with old C code. You can find resulting code at my github account.

Here you can see example run with 10 customers, 3 seats in barber shop, haircut takes 15 ms, customers are coming every 10 ms and returning after 20 ms. You can change all parameters if you want.

barber run