3 ms·
>foreach will not be replaced behind the scenes into multithreaded version since it changes behaviour. It only (meaningfully) changes behavior if you're both i
by Gh0stRAT 3y ago
>foreach will not be replaced behind the scenes into multithreaded version since it changes behaviour.
It only (meaningfully) changes behavior if you're both iterating over an odered datastructure and the body of your loop has direct or indirect side-effects. (like printing, writing to a file, making network requests, etc)
- dragonwriter 3y ago> It only (meaningfully) changes behavior if you're both iterating over an odered datastructure and the body of your loop has direct or indirect side-effects. Right, and not always even then, because that depends on what the consumer is concerned with as well. But the fact that it can means it's not a safe automatic substitution.
- tester756 3y ago>nd the body of your loop has direct or indirect side-effects So like... huge % of the real world code bases
- Gh0stRAT 3y agoUnfortunately yes. That being said, the hottest loops that would benefit the most from added parallelism tend to have fewer side effects already in my experience so things aren't quite so bleak.