本文共 613 字,大约阅读时间需要 2 分钟。
Concurrency in practice
- Avoid blocking,avoid race conditions
- Use channels to avoid shared state. Use select to manage channels.
- where channels don't work:
- try to use tools from the sync package first
- in simple cases or when really needed:try lockless code
Guidelines for non-blocking code
- Don't switch between atomic and non-atomic functions
- Target and exploit situations which enforce uniqueness
- Avoid changing two things at a time
- Sometimes you can exploit bit operations
- Sometimes intelligent ordering can do the trick
- Sometimes it's just not possible at all
转载于:https://juejin.im/post/5c1ba833f265da611b58515f