4 ms·
I was with you until you said "concurrently usable containers." While they aren't standard, they do exist in C++ (Intel Threading Building Blocks and whatever
by maxlybbert 11y ago
I was with you until you said "concurrently usable containers." While they aren't standard, they do exist in C++ (Intel Threading Building Blocks and whatever Microsoft called it's clone of Intel TBB), and they aren't as useful as people believe. C#'s concurrent containers have the same limitations, and to the extent I've used them, Java concurrent containers have the same limitations.
The limitations I'm thinking of is that it's very common to need to do more than one operation atomically, and common concurrent containers are unable to do that. You can atomically add or remove a single item from a concurrent queue, stack or hash map, and sometimes that's enough. But if you want to iterate a whole container, say searching for all items that meet some criteria, you need a lock.
- pkolaczk 11y agoTo iterate the whole container, I don't need a lock. I just use a container that offers cheap immutable snapshots, e.g. Scala TrieMap and I store only immutable items in it. Doing similar structures in C++ is much harder if not impossible without efficient GC.
- ehvatum 11y agoI have to say, I have been pleasantly surprised time and time again by the powerful ease of data-structure-heavy algorithm implementation afforded by thread-safe, atomic std::shared_ptr, the rest of <memory> and <atomic>, judicious use of move semantics and open mp. It's also a huge relief to have deterministic deallocation back in my life. Praise Jesus for that. It's not everyone's cup of tea, but if you need the speed, it's there for you - with a solid, clean and expressive implementation. Your classic symbolic regression genetic algorithm with halls-of-fame and whatnot is an absolute cinch, for example, and runs gob-smackingly fast with -O3 -march=native, and a good ten minutes of profiling data for pgo.