thread priorities?

Bulat Ziganshin bulat.ziganshin at gmail.com
Sat Apr 1 09:26:11 EST 2006


Hello Simon,

Friday, March 31, 2006, 4:57:19 PM, you wrote:

>>>> threadSetPriority :: ThreadID -> Int -> IO ()
>>
>> it was requested by Joel Reymont, and he even give us information how
>> that is implemented in Erlang, together with hint to assign higher
>> priorities to consuming threads.

> Yes, but the Erlang implementation doesn't do anything about priority
> inversion.  Also, I don't think Joel really wanted priorities, his
> problem could have been solved by using bounded channels.

to be exact, his problem (1000 producers and one consumer) can be
solved ONLY by using some bounded queue. but for typical usage when
there are one or several producers and one consumer, priorities allow
to solve problem:

1) in easier and more intuitive way, that is well known from other
environments (Unix, for example)
2) without introducing new data structures - bounded channels, bounded
priority queues and so on, so on (although it should be easy to
construct them)

priorities are also useful for solving other problems, where bounded
queues can't help us. as i said, my own program contains one thread that
reads thousands of files from disk and pushes their data into the
queue. then other threads process these data. as you can see, first
thread is I/O-bound while other is CPU-bound. of course, i want to
give higher priority to the first thread so that it reads next portion
of data as soon as previous read operation is complete (and there is
free buffer). how can i accomplish it with current ghc implementation?


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



More information about the Haskell-prime mailing list