RwLock slow to acquire read lock even when uncontended

Ah! That's exactly the sort of thing I was hoping to come up with.

I was worried that the list of fixed particles may grow large, so copying it each time a particle is added, could be expensive. But if it is really only treated as a list, a persistent data structure would make the append/copy very cheap.

I see, thanks. I guess my confusion stemmed from not realizing that merely acquiring read locks on a RwLock (even though that supports multiple concurrent readers) is far from free, and can create a lot of contention.

In a way I'm already doing that, since I'm using a cell list to detect collisions. Currently I wrapped the entire cell list in a RwLock, but I'll see if I can do the locking on a finer-grained level (on a per-cell basis).

I know :wink: The reason for the -1 was that I was using one "special" thread to also handle output (not in the example code).

Hmm, that is true. I didn't realize that.

Interesting idea, thanks! I'll look into it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.