jon.recoil.org

Module Multicore

Multicore allows spawning preemptively scheduled threads to run on domains running in parallel.

val max_domains : unit -> int @@ portable

max_domains () is the maximum number of domains. Domains are indexed from 0 to max_domains () - 1.

val current_domain : unit -> int @@ portable

current_domain () is the index of the domain that the current thread is running on.

  • raises Invalid_argument

    in case current_domain () is not called from the initial domain or one of the other domains managed by this library.

type ('a : value_or_null) spawn_result =
  1. | Spawned
  2. | Failed of 'a * exn @@ many aliased * Printexc.raw_backtrace @@ many aliased
val spawn_on : ('a : value_or_null). domain:int -> ('a @ unique once portable contended -> unit) @ once portable -> 'a @ unique once portable contended -> 'a spawn_result @ unique once portable contended @@ portable

spawn_on ~domain action spawns action as a thread running on the specified domain.

The action should handle all exceptions. In case the action raises an exception, it will be allowed to propagate and the uncaught exception handler will be called.

  • raises Invalid_argument

    in case the domain index is less than 0 or greater than max_domains () - 1.

  • raises Sys_error

    in case the system fails to create a new thread.

val spawn : ('a : value_or_null). ('a @ unique once portable contended -> unit) @ once portable -> 'a @ unique once portable contended -> 'a spawn_result @ unique once portable contended @@ portable

spawn action spawns action as a thread running on some domain.

The action should handle all exceptions. In case the action raises an exception, it will be allowed to propagate and the uncaught exception handler will be called.

The domain used to spawn the thread on is selected semi-probabilistically so as to balance the load per domain.

  • raises Sys_error

    in case the system fails to create a new thread.