unsafeInterleaveST is too unsafe
Several years ago, Edward Kmett wrote a blog post that (among other things) explains that unsafeInterleaveST is not thread-safe; actions may be performed multiple times.
The fix that would seem to match everything else best would be to rename unsafeInterleaveST to unsafeDupableInterleaveST and define unsafeInterleaveST m = unsafeDupableInterleaveST (noDuplicate >> m) using an STish version of noDuplicate.
As Kmett explains, the dupable version is useful for high performance when the suspended action is known to be idempotent. Actually, the action being idempotent is insufficient, but I believe a sufficient condition is that the action does not both read and write any reference or array element.
While we're at it, we need to document all the functions in Control.Monad.ST.Unsafe.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Core Libraries |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |