What practice or practices are good 90% of the time when working with threading with multiple cores?
Personally all i have done w开发者_运维问答as share immutable classes and pass (copy) data to a queue to the destine thread.
This is very vague - but there are a few basic precepts I'd always follow:
- Make sure threading makes sense before you implement it
- Focus on algorithms, not individual lines of code when designing for threading
- Thread at the highest level possible
- Prefer immutable data
- Synchronize data access appropriately
- Prefer high level threading libraries over low level, hand written threading code
- Measure (make sure 1. was true!)
精彩评论