5 ms·
So to check, I googled C++11 threads memory model, and it[0] looks like his main complaint isn't helped by C++ 11 threads, as they essentially allow shared stat
by noobermin 9y ago
So to check, I googled C++11 threads memory model, and it[0] looks like his main complaint isn't helped by C++ 11 threads, as they essentially allow shared state too. They are also a thin veneer over the OS threads, for unix types, pthreads I imagine.
[0] http://en.cppreference.com/w/cpp/language/memory_model http://en.cppreference.com/w/cpp/language/memory_model
- duneroadrunner 9y agoYeah, I don't know if there's ever going to be a portable way to enforceably "disallow" the sharing of state between threads in C++. For straightforward cases, the SaferCPlusPlus library provides an easy way to "wrap" any object so that access from different threads is safely controlled[1]. [1] shameless plug: https://github.com/duneroadrunner/SaferCPlusPlus#asynchronously-shared-objects https://github.com/duneroadrunner/SaferCPlusPlus#asynchronou...
- jcelerier 9y ago> Yeah, I don't know if there's ever going to be a portable way to enforceably "disallow" the sharing of state between threads in C++. Not sharing state at all means that you cannot even do message passing other than through sockets or something like this. At some point you have to share at least a message queue to be able to go from thread A to thread B.
- fnj 9y agoHonest question: If you aren't going to share data between/among threads, why use threads at all? Why not just fork-abd-exec?
- danieltillett 9y agoBecause on windows it is much slower.
- to3m 9y agoIf it's the same, it's the same, so there's no reason to do one rather than the other. Why not just create a thread?
- thristian 9y agoSharing (immutable) data between threads is fine, you just don't want to share (mutable) state or else you run the risk of threads stomping on each other. The ideal scenario is map/reduce: you take some large chunk of data, divide it up into smaller chunks, spin up a thread to process each smaller chunk and produce a result. Once the threads have all completed and the results are no longer changing, the main thread can pick them up and combine them to a single result. It's possible to do that with fork-and-exec, but without a shared address space, marshalling costs make it expensive.