4 ms·
So how do you implement multithreading if the above are a bad idea?
by mihaigalos 4y ago
So how do you implement multithreading if the above are a bad idea?
- JonChesterfield 4y agoDeep copy on passing between threads. Interesting pros and cons to the performance of that vs sharing pointers.
- mgaunard 4y agoThere is no need to copy objects for multiple threads to refer to them. It's just that there is a single owner, and the other threads have a non-owning view only. You need strict control on the thread lifetime, which is enforced through the same single ownership system, in order to enforce this.
- mgaunard 4y agoThe thread lifetime is also scope-bound, to ensure the thread dies before any object it might be referring to does.
- mihaigalos 4y agoSorry, I meant how to guard against race conditions where multiple threads try to write to the same shared memory? This is clasically done via memory synchronization mechanisms/atomics.
- mgaunard 4y agoI don't understand how this has anything to do with lifetime management, which is what GC/RC/ARC are for. You do need to synchronize concurrent access to the same object, and it's not just concurrent writes, it's concurrent accesses if at least one of them is a write.