.net - What should I use spin lock or mutex if conflict doesn't occur often -
i'm fixing 1 bug related concurrent access collections in 1 library. library uses mutex(lock) control access multiple threads. locked areas in code contains code should executed quite fast (modifying list/dictionary or read it) spin lock seems match scenario.
but ... in cases lock not necessary because majority of apps uses library single-threaded , important me not slow them down. mine naive benchmark indicates spin lock checks slower resource not used, not trust it.
if advertising function thread safe should provide locking on collection updates.
if not, make sure document fact , leave consumer.
Comments
Post a Comment