3 ms·
Yeah, CSP is awesome. The traditional thing to do here is to use immutable data structures; because they can never change, you don't need locks to access them,
by david-given 10y ago
Yeah, CSP is awesome.
The traditional thing to do here is to use immutable data structures; because they can never change, you don't need locks to access them, which means you can pass pointers between threads willy-nilly. And if you're sending a message to a process that doesn't share memory, you can fall back to serialisation.
Bear in mind that you can still get race conditions and deadlocks with CSP --- consider a process which provides `get` and `set` messages, and then two other processes try to do `c.set(c.get() + 1)`.
- rix0r 10y agoSaying "use immutable data structures" here assumes garbage collection though. If you didn't have garbage collection, when would you release the memory for these structures? That would bring you back to refcounting.
- Rexxar 10y agoIs it a problem in practice to use reference counting for an "immutable data structures" ? Obviously it's not 100% immutable as the counters are updated. But if it's done with a thread safe reference counter the data structures is usable like a pure immutable data structure and doesn't need an additional garbage collector.
- deleted 10y ago[deleted]
- david-given 10y agoOh, yeah, I missed that bit of context. Oops. OP's comment makes much more sense now...