Victor Sergienko
Victor Sergienko

Reputation: 13495

ReaderWriterLockSlim (not so slim) replacement, recursive, with upgradeable read?

Somehow we got a LOT of ReaderWriterLockSlim in our code. Each of them takes 6K memory, so this has become a big issue.

As a quick fix, I'm looking for a less memory-hungry replacement. I'm trying a Joe Duffy's RW-lock, but it's not upgradeable and write-recursive (and is pretty hard to make it such).

Is there any other, more memory-light replacement?

Upvotes: 2

Views: 303

Answers (2)

Victor Sergienko
Victor Sergienko

Reputation: 13495

In case someone else needs a memory-lighter RW lock with the same semantics as ReaderWriterLockSlim:

  • upgradeable;
  • recursive;
  • lock belongs to a thread, so, for instance, recursive W-locks are OK, or R-lock from inside W-lock is OK;

the one from Mono source should be OK.

Upvotes: 0

Well, an obvious approach would be to use ReadWriterLock (sans Slim), which I believe is less memory intensive (but also less efficient in some scenarios).

Upvotes: 1

Related Questions