Hello Andras,

Monday, May 26, 2014, 1:10:27 PM, you wrote:

thank you. i've wrote my own version although doubt whether it will be exception-safe.
it's a sketch:

data WorkerThreadPool a =
    WTP QSem (MVar [(Int,a)]) Int

createWorkerThreadPool num_threads = do
    x <- newQSem 0
    y <- newMVar []
    return$ WTP2 x y num_threads

runInWorkerThreadPool (WTP sem jobs _) prio job = do
    modifyMVar jobs (++[(prio,job)])
    signalQSem sem

getJob (WTP sem jobs _) = do
    waitQsem sem
    job <- modifyMVar jobs (splitAt 1)



STM is very simple to use, you create transactions in the STM monad (actions that should be executed as an atomic unit) then execute them with atomically :: STM a -> IO a. Under the hood the STM monad creates a dependency graph of the used STM primitives (TVars) in order to know when to undo/redo transactions. But from what I understand you'll pretty much only need to use (atomically . readTChan c)/(atomically . writeTChan c) which are in the IO monad




-- 
Best regards,
 Bulat                            
mailto:Bulat.Ziganshin@gmail.com