<div dir="ltr">Hi friends,<div><br></div><div>I am writing a library that has Handle-like values for resources that are not thread-safe (foreign state from a non-thread-safe C library). In other words, a resource can only be "used" by one Haskell thread at a time. Unless I take steps, if one shares the resource between concurrent Haskell threads, bad things will happen at runtime (even with a single-threaded runtime).</div><div><br></div><div>Naturally, I want consumers to use my library safely, so I am considering making it safe for all by pessimistically enforcing safe usage with MVars.<br></div><div><br></div><div>Is it common/expected that Haskell libraries enforce safe access like this?</div><div><br></div><div>MVars are not free from cost, but are they cheap (i.e. almost as fast as no forced synchronization) as long as no blocking/rescheduling occurs?<br></div><div><br></div><div>Thanks,<br></div><div>--</div><div>Thomas Koster</div><div><br></div></div>