2 ms·
And a mutex that you never take is cheaper than one that you do. Taking the (f)mutex is fast but any context switch will be brutal if you're really using thread
by vvanders 9y ago
And a mutex that you never take is cheaper than one that you do. Taking the (f)mutex is fast but any context switch will be brutal if you're really using threading to increase your performance.
That said I'm used to situations where we're pinning thread affinity to specific cores and really trying to squeeze out what you can from fixed resources.
- exDM69 9y agoPinning threads to cores with affinity is another technique that should be used with caution. Under normal circumstances the kernel will run the same thread on the same core as much as possible because CPU migration is expensive. Setting CPU affinity will ensure that you always get the same core, but it might not increase performance and could adversely affect other parts of the system. CPU affinity is a good fit for continuously running things like audio processing or game physics or similar. It's not good when threads are blocked or react to external events. In most cases it's just unnecessary because the kernel is pretty good in keeping threads on cores anyway.