Search code examples
delphifork-joinomnithreadlibrary

Does OmnithreadLibrary support "work stealing"?


Work stealing is for example available in the Fork / Join framework on the Java platform. (See How is the fork/join framework better than a thread pool?) - is something similar possible with the OmniThreadLibrary?


Work stealing: worker threads that run out of things to do can steal tasks from other threads that are still busy.


Solution

  • I don't know if I would call this technique "work stealing" but indeed OmniThreadLibrary keeps all your cores busy when executing Fork/Join abstraction.

    When you use Fork/Join, you send a task into the computation pool by calling Compute. When you call Value to get the result of the subcomputation or Await to wait on the subcomputation to finish and the subcomputation has not completed its work yet, Value/Await will take another task from the computation pool and execute it. When this new task is finished, it will again check whether the subcomputation has completed its work and if not it will process next subtask.

    This mechanism is further described on the OmniThreadLibrary wiki.


    EDIT

    I don't think Fork/Join approach should be called "work stealing". In OmniThreadLibrary implementation, work item is never assigned to a thread until the thread starts executing it. And once the thread starts executing it, nobody can steal it as there would be no purpose in that.