Page 1 of 1

global task priority

Posted: Wed Aug 05, 2015 3:52 pm
by fewl9012
Is task priority global? If so, then it's all wrong. Suppose I'm writing some routines that use tasks. My routines are called by something written by someone else, and that person is also using a library written by a third person. I don't know what the priority of the task my routine is called in, so I can't reliably create a task that I know has a higher or lower priority than I have. I may use 10 as my low priority value and 100 has my high priority value, but my caller may use 0 as low priority and 2 as high priority. To make my routines interoperable with my caller and the third person library, I need to pass extra state around holding the priorities.

A better method would be to make priority relative to the priority of the current task, with positive or negative values. Perhaps even allowing negative priority values. Then you'd need a minimum value, but the minimum need not be the default. Failing any of that, at least an API routine to return the priority of the current task.

Counterarguments that "It's just a hint!" or "The implementation can ignore priorities!" or "You can't rely on priorities anyway!" are all stupid. If priorities aren't important, remove them and simplify the spec and all implementations. if they aren't important, they shouldn't be added. If they are important, they need to promote interoperability.