How can I set the priorities of tasks in async or lwt

You have precisely got this, cvine.

I have cpu-bound search tasks, the model is like searching exits in a maze. At each node, I may spawn search functions (threads) for this. Since most searches can be unbound for my question, I hope to have a priority queue in which I can specify the search policy.

I didn’t say here that we do have a priority queue of functions and executed sequentially. The legacy code is based on handwritten free monads for nondeterminism. We also have pub/sub functions in it. (It’s an academic project through, people take turns to maintain it). Please believe I do need to update it, or have to replace some parts on my own).

Therefore, I hope there is an existing public library, or I can adapt onto it, to achieve a framework which I can make coroutines, yield them, composite them and their callbacks, broadcast signals, and pick ones with high-priorities run for a bit.

As for Lwt (or Async), Lwt has a core library and a Unix binding library. The core library has no I/O at all. The APIs look appealing if only I can check priority-based in achievable. That’s my main purpose of this post. I might go a bit further in this post and it’s possible finally I can come back to write my own scheduling.

I also agree with your point that priority might be of real value with multicore. I also admit here the critical reason for priority is not for efficiency, but to avoid to be trapped in some searches.