package lwt

  1. Overview
  2. Docs

This module allows to mix preemptive threads with Lwt cooperative threads. It maintains an extensible pool of preemptive threads to which you can detach computations.

val detach : ('a -> 'b) -> 'a -> 'b Lwt.t

detaches a computation to a preemptive thread.

val run_in_main : (unit -> 'a Lwt.t) -> 'a

run_in_main f executes f in the main thread, i.e. the one executing Lwt_main.run and returns its result.

val init : int -> int -> (string -> unit) -> unit

init min max log initialises this module. i.e. it launches the minimum number of preemptive threads and starts the dispatcher.

  • parameter min

    is the minimum number of threads

  • parameter max

    is the maximum number of threads

  • parameter log

    is used to log error messages

    If Lwt_preemptive has already been initialised, this call only modify bounds and the log function, and return the dispatcher thread.

val simple_init : unit -> unit

simple_init () does a simple initialization. i.e. with default parameters if the library is not yet initialised.

Note: this function is automatically called detach.

val get_bounds : unit -> int * int

get_bounds () returns the minimum and the maximum number of preemptive threads.

val set_bounds : (int * int) -> unit

set_bounds (min, max) set the minimum and the maximum number of preemptive threads.

val set_max_number_of_threads_queued : int -> unit

Sets the size of the waiting queue, if no more preemptive threads are available. When the queue is full, detach will sleep until a thread is available.

val get_max_number_of_threads_queued : unit -> int

Returns the size of the waiting queue, if no more threads are available

OCaml

Innovation. Community. Security.