1 comments

  • i_am_a_peasant2 hours ago
    You know it often is the case that APIs like this both in C++ and Rust don&#x27;t offer you enough knobs when your usecase deviates from being trivial.<p>It happens with locking APIs, it happens with socket APIs, anything platform dependent.<p>Does the C++ standard give you an idiomatic way to set PTHREAD_RWLOCK_PREFER_READER_NP or PTHREAD_RWLOCK_PREFER_WRITER_NP explicitly when initializing a rwlock? Nope. Then you either roll your own or in Rust you reach for a crate where someone did the work of making a smarter primitive for you.
    • VorpalWay1 hour ago
      Yeah, you can&#x27;t enable priority inheritance for mutexes in std of either C++ or Rust. Which is a show stopper for hard realtime (my dayjob).<p>And then you have mutexes internally inside some dependency still (e.g. grpc or what have you). What I would really like is the ability to change defaults for all mutexes created in the program, and have everyone use the same std mutexes.<p>By the way: rwlocks are often a bad idea, since you still get cache contention between readers on the counter for number of active readers. Unless the time you hold the lock for is really long (several milliseconds at least) it usually doesn&#x27;t improve performance compared to mutexes. Consider alternatives like seqlocks, RCU, hazard pointers etc instead, depending on the specifics of your situation (there is no silver bullet when it comes to performance in concurrent primtitves).
      • jcalvinowens1 hour ago
        &gt; What I would really like is the ability to change defaults for all mutexes created in the program, and have everyone use the same std mutexes.<p>Assuming you&#x27;re building the whole userspace at once with something like yocto... you can just patch pthread to change the default to PTHREAD_PRIO_INHERIT and silently ignore attempts to set it to PTHREAD_PRIO_NONE. It&#x27;s a little evil though.<p>&gt; By the way: rwlocks are often a bad idea<p>+1
        • VorpalWay7 minutes ago
          That is a great terrible idea (I really have to think a bit more on that). Won&#x27;t help for Rust, since the mutexes there use futex directly, so you would have to patch the standard library itself (and for futex it is more complex than just enabling a flag). Seems plausible that other libraries and language runtimes might do similar things.
        • i_am_a_peasant1 hour ago
          i think both you guys have the same job as me lol