Ticket #4329 (new feature request)

Opened 3 years ago

Last modified 8 months ago

GHC.Conc modifyTVar primitive

Reported by: dmbarbour Owned by:
Priority: low Milestone: 7.6.2
Component: Compiler Version: 6.12.3
Keywords: TVar, STM, modifyTVar, Concurrency Cc: tharris@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

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.

Change History

Changed 3 years ago by simonpj

  • cc tharris@… added

Tim Harris writes: not sure if this is what the original authors intend, but one option would be to execute all these modifications at commit-time.

I.e. the log entry would be <tvar, f> pairs for these tvars, rather than <tvar, old, new> triples.

At commit time these entries would be expanded to <tvar, old, new> triples, and then attempt to be committed in the normal way.

If there is a subsequent conflict on one of these tvars then "f" would be re-evaluated and then the commit re-started.

There'd be some details to work through if the same tvar is read/written directly in the same tx.

Changed 3 years ago by igloo

  • milestone set to 7.2.1

Changed 16 months ago by igloo

  • priority changed from normal to low
  • milestone changed from 7.4.1 to 7.6.1

Changed 8 months ago by igloo

  • milestone changed from 7.6.1 to 7.6.2
Note: See TracTickets for help on using tickets.