thread priorities?

Benjamin Franksen benjamin.franksen at
Tue Apr 4 13:03:37 EDT 2006

On Saturday 01 April 2006 16:26, Bulat Ziganshin wrote:
> 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?

I think you cannot, at least not without implementing your own (priority 
based) scheduler ;)

Thread priorities are seldom needed, but /if/ you need them, there is 
really no practical way around them.

My standard example is motion control. You have a thread for the 
low-level feedback loop, and one or more threads for high-level motion 
planning. The latter is usually a lot more CPU-intensive, but the 
former needs to run whenever enough data is available (usually from 
some position or velocity readback device). For such applications, 
priority based (preemptive) scheduling is the only practical solution I 
know of.

I would argue that /some/ support for thread priorities should be in the 
standard, maybe as an extension.


More information about the Haskell-prime mailing list