Chan with priorities

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Chan with priorities

Bulat Ziganshin-2
Hello Haskell-cafe,

can  you please point me to any OSS implementation of IO Channels with
priorities  -  i.e. data pushed to the Chan using high priority should
be read prior to the data pushed with lower priority:

pushChan ch 1 'x'
pushChan ch 2 'y'
readChan ch >>= print -- prints 'y'

i've  found only STM implementations - i don't know STM enough, may be
i just need to convert STM to IO operations?

i  don't  expect  strong  guarantees, my algorithm will remain correct
anyway. and i don't have lot of objects, it's just a few dozens

 

--
Best regards,
 Bulat                          mailto:[hidden email]

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Chan with priorities

Andras Slemmer
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


On 26 May 2014 11:01, Bulat Ziganshin <[hidden email]> wrote:
Hello Haskell-cafe,

can  you please point me to any OSS implementation of IO Channels with
priorities  -  i.e. data pushed to the Chan using high priority should
be read prior to the data pushed with lower priority:

pushChan ch 1 'x'
pushChan ch 2 'y'
readChan ch >>= print -- prints 'y'

i've  found only STM implementations - i don't know STM enough, may be
i just need to convert STM to IO operations?

i  don't  expect  strong  guarantees, my algorithm will remain correct
anyway. and i don't have lot of objects, it's just a few dozens



--
Best regards,
 Bulat                          mailto:[hidden email]

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Chan with priorities

Bulat Ziganshin-2
Re: [Haskell-cafe] Chan with priorities 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                            
[hidden email]
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Chan with priorities

Yitzchak Gale
In reply to this post by Bulat Ziganshin-2
Bulat!
It's great to see you here.
We haven't seen you in quite a while.

Regards,
Yitz

On Mon, May 26, 2014 at 12:01 PM, Bulat Ziganshin
<[hidden email]> wrote:

> Hello Haskell-cafe,
>
> can  you please point me to any OSS implementation of IO Channels with
> priorities  -  i.e. data pushed to the Chan using high priority should
> be read prior to the data pushed with lower priority:
>
> pushChan ch 1 'x'
> pushChan ch 2 'y'
> readChan ch >>= print -- prints 'y'
>
> i've  found only STM implementations - i don't know STM enough, may be
> i just need to convert STM to IO operations?
>
> i  don't  expect  strong  guarantees, my algorithm will remain correct
> anyway. and i don't have lot of objects, it's just a few dozens
>
>
>
> --
> Best regards,
>  Bulat                          mailto:[hidden email]
>
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Chan with priorities

Felipe Lessa
Em 26-05-2014 10:51, Yitzchak Gale escreveu:
> Bulat!
> It's great to see you here.
> We haven't seen you in quite a while.

Same thought I had, but I dismissed it thinking that I must have just
missed his e-mails :).

Cheers,

--
Felipe.


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe

signature.asc (919 bytes) Download Attachment