I've been working on multithreaded code that passes references around. If you hold the reference, you have exclusive access for reading and writing the data at the reference. In theory you should only send values between threads when you need to pass exclusive access to a thread. At all other times, data is completely sharded between threads. The only reason to pass a reference around is to pass data between threads, similar to a queue but not quite. I deliberately avoid updating shared data structure such as a list that both threads are processing. Instead, each thread gets a shard.
I get 6,359,793 requests per second of passing reference around with this approach. Ideally each reference should correspond to a large amount of CPU work (at least 1 second), so that you shouldn't need to pass around references between threads that fast. This is 150 nanoseconds for a synchronization event, roughly 1.5 memory accesses.
I read a whitepaper on value semantics: https://arxiv.org/pdf/2106.12678.pdf
I think it's promising.
I've been working on multithreaded code that passes references around. If you hold the reference, you have exclusive access for reading and writing the data at the reference. In theory you should only send values between threads when you need to pass exclusive access to a thread. At all other times, data is completely sharded between threads. The only reason to pass a reference around is to pass data between threads, similar to a queue but not quite. I deliberately avoid updating shared data structure such as a list that both threads are processing. Instead, each thread gets a shard.
I get 6,359,793 requests per second of passing reference around with this approach. Ideally each reference should correspond to a large amount of CPU work (at least 1 second), so that you shouldn't need to pass around references between threads that fast. This is 150 nanoseconds for a synchronization event, roughly 1.5 memory accesses.