thread safe and what parts are not? (from parts I mean for example map , ...)
2-when to use mutexes ?
and when to use channels ?
3-what is select statement and it's usecases?
4- can we understand that code has coroutines conflicts without running go race detector command?
1. Most things are not thread safe, if the doc doesn't say thread safe it is not 2. Try not to use mutexes. Also I don't like the name, bottlenecks is a far better name. Use channels instead wherever possible 3. Select waits (yields) until data is available or a condition is met. This is very useful when a coroutine must wait for several events 4. Yes, it will require quite an understanding of how go scheduling and coroutine system works
2- which one is better for performance and memory usage between mutex and channel? 4- I meant for example when we using a library we don't know how that library implemented (thread-safe or not) unless read the whole library code
2. generally the channel is better in its worst case and the mutex is better in its best case. This means that channels basically scale better in terms of accesses than mutexes 4. Read the doc. If the docs of a library don't say something is thread safe, it is generally advised to take it for not thread safe
1. pretty much nothing. You have to synchronize explicitly most of the time 2. when you've got mutable state shared across goroutines 3. oh, come on, you didn't pass The Tour of Go, did you? 4. no.
channels don't make sense when what you've got is shared state. channels are for inter-goroutine communication
That is the kind of moments when using goroutines as agents helps
a mutex is always way cheaper than a channel
afaik, failing to lock a mutex is fairly expensive
channels scale better? how so and why?
and thank you Mr.Sharkov 😊 btw your "sched" was cool
it can help in some cases, but it's always going to be wasted performance sometimes a mutex is just simpler and cheaper
a channel is built upon multiple mutexes. It's always more expensive than a mutex
No the channel implementation of go does not actually use mutexes
https://github.com/golang/go/blob/master/src/runtime/chan.go
Обсуждают сегодня