3 ms·
> Message passing is just outsourcing the lock, right? Kind of. If you can architect such that each channel has exactly 1 reader and 1 writer, you can send mes
by adgjlsfhk1 2y ago
> Message passing is just outsourcing the lock, right?
Kind of. If you can architect such that each channel has exactly 1 reader and 1 writer, you can send messages in a single direction with no locks. The basic idea is that you have a circular buffer with a start index and an end index. The writer can write an element and increment the end index (as long as end index+1<start index which doesn't have to be done atomically), while the reader can just read an element and increment the start index (as long as start index +1 < end index). This strategy needs to use atomic operations (which are basically free when uncontested, which they will be as long as the queue has a few elements in it)