Reference:
std::shared_mutex
pthread_rwlock_init
stackoverflow response:
https://stackoverflow.com/a/57709957
https://stackoverflow.com/a/2190271
Take away:
C++17's std::shared_mutex on linux might using pthread_rwlock_t underneath, thus in order to tweak
the behavior of write starvation, set PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP in the pthread_rwlock_init call's pthread_rwlockattr_t is necessary.
For those not using pthread_rwlock_t, std::shared_mutex should rely on linux kernel's scheduler, which is fair, avoid either write/read starvation.
Here's how Go handles stavation:
http://vsdmars.blogspot.com/2021/03/go-methods-for-lock-starvation-barging.html
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.