priority-sync: Cooperative task prioritization.
In a simple use case, we want to run some expensive tasks in prioritized order, so that only one task is running on each
CPU (or hardware thread) at any time. For this simple case, four operations are needed: simpleTaskPool,
schedule, claim, and startQueue.
let expensiveTask = threadDelay 1000000 pool <- simpleTaskPool forkIO $ claim Acquire (schedule pool 1) $ putStrLn "Task 1 started . . ." >> expensiveTask >> putStrLn "Task 1 completed." forkIO $ claim Acquire (schedule pool 3) $ putStrLn "Task 3 started . . ." >> expensiveTask >> putStrLn "Task 3 completed." forkIO $ claim Acquire (schedule pool 2) $ putStrLn "Task 2 started . . ." >> expensiveTask >> putStrLn "Task 2 completed." threadDelay 100000 -- contrive to wait for all tasks to become enqueued putStrLn "Starting pool: " startQueue pool threadDelay 4000000 -- contrive to wait for all tasks to become dequeued
A TaskPool combines Rooms and Queues in an efficient easy-to-use-interface.
Rooms provide fully reentrant synchronization to any number of threads based on arbitrary resource constraints.
For example, the Room from a simpleTaskPool is constrained by GHC.numCapabilities.
Queues provide task prioritization. A Queue systematically examines (to a configurable depth) all waiting threads with their
priorities and resource constraints and wakes the most eagerly prioritized thread whose constraints can be satisfied.
TaskPools are not thread pools. The concept is similar to IO Completion Ports. There are no worker threads. If a number of threads are waiting,
the thread that is most likely to be processed next is woken and temporarily serves as a working thread.
Rooms, Queues, and TaskPools are backed by carefully written STM (software transactional memory) transactions.
A salient feature is that, because any thread can participate, a TaskPool supports both bound threads and threads created with forkOnIO.
The git repository is available at http://www.downstairspeople.org/git/priority-sync.git.
Modules
[Index]
Downloads
- priority-sync-0.1.0.1.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
For package maintainers and hackage trustees
Candidates
- No Candidates
| Versions [RSS] | 0.1.0.0, 0.1.0.1, 0.2.1.0, 0.2.1.1 |
|---|---|
| Dependencies | base (>3), containers (>=0.1.0.1), heap, parallel (>=1.0.0.0), random, stm (>=2.1.1.2) [details] |
| Tested with | ghc ==6.10.1 |
| License | BSD-3-Clause |
| Author | Christopher Lane Hinson |
| Maintainer | Christopher Lane Hinson <lane@downstairspeople.org> |
| Category | Concurrency |
| Uploaded | by ChristopherLaneHinson at 2009-04-29T18:21:02Z |
| Distributions | NixOS:0.2.1.1 |
| Reverse Dependencies | 2 direct, 0 indirect [details] |
| Executables | _Control_Concurrent_Priority_Tests |
| Downloads | 3407 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] |