stm-linkedlist: Mutable, doubly linked lists for STM

[ bsd3, data, library ] [ Propose Tags ] [ Report a vulnerability ]

Doubly linked lists are often used in imperative languages to maintain a collection of objects such that an object can remove itself easily. The same idea applies here. Thanks to STM, these lists can be shared among threads with little effort.

Suppose you have a thread listening for events. You want to dispatch events to any thread that opts in. You could write a function that installs an event handler, performs an action, and removes the handler:

withEventHandler list handler action =
    bracket (atomically $ LinkedList.append handler list)
            (atomically . LinkedList.delete)
            (\_ -> action)

Then, you could have your listener thread dispatch events using a function like this:

dispatchEvent list event = do
    handlers <- atomically $ LinkedList.toList list
    forM_ handlers $ \handler -> handler event

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Dependencies base (>=4 && <5), stm [details]
License BSD-3-Clause
Copyright Copyright (c) Joseph Adams 2011
Author Joey Adams
Maintainer joeyadams3.14159@gmail.com
Category Data
Source repo head: git clone git://github.com/joeyadams/haskell-stm-linkedlist.git
Uploaded by JoeyAdams at 2011-10-20T16:57:03Z
Distributions NixOS:0.1.0.0
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 1428 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]