Ticket #4329 (new feature request)
GHC.Conc modifyTVar primitive
|Reported by:||dmbarbour||Owned by:|
|Keywords:||TVar, STM, modifyTVar, Concurrency||Cc:||tharris@…|
|Type of failure:||None/Unknown||Difficulty:|
|Test Case:||Blocked By:|
I would like modifyTVar as a 'write-only' primitive supported by GHC's STM.
The semantic definition is:
modifyTVar :: TVar a -> (a -> a) -> STM () modifyTVar v f = readTVar v >>= writeTVar v . f
However, explicitly reading then writing the TVar introduces unnecessary interference between transactions. The value held by the TVar does not affect the behavior of the transaction. modifyTVar should not interfere with other transactions that only writeTVar or modifyTVar.
Even if a non-interfering implementation isn't feasible due to the underlying implementation of GHC's STM, providing the function would provide a point for a transparent upgrade in the future.