Module EioSource

Effects based parallel IO for OCaml.

Eio provides support for concurrency (juggling many tasks) and parallelism (using multiple CPU cores for performance).

It provides facilities for creating and coordinating fibers (light-weight threads) and domains (for parallel processing), as well as interfaces for interacting with resources provided by the operating system.

These features must be used within an event loop, provided by an Eio backend. Applications can use Eio_main.run to run a suitable loop.

See https://github.com/ocaml-multicore/eio for a tutorial.

Sourcemodule Std : sig ... end

Commonly used standard features. This module is intended to be opened.

Fibers

Sourcemodule Switch : sig ... end

Grouping fibers and other resources so they can be turned off together.

Sourcemodule Fiber : sig ... end

A fiber is a light-weight thread.

Sourcemodule Cancel : sig ... end

Cancelling fibers.

Concurrency primitives

Sourcemodule Promise : sig ... end

A promise is a placeholder for result that will arrive in the future.

Sourcemodule Semaphore : sig ... end

A counting semaphore.

Sourcemodule Mutex : sig ... end

Mutual exclusion.

Sourcemodule Condition : sig ... end

Waiting for a condition to become true.

Sourcemodule Lazy : sig ... end

Delayed evaluation.

Collections

Sourcemodule Stream : sig ... end

A stream/queue.

Sourcemodule Pool : sig ... end

A pool of resources.

Multiple domains

Sourcemodule Domain_manager : sig ... end

Parallel computation across multiple CPU cores.

Sourcemodule Executor_pool : sig ... end

A pool of domains for executing jobs.

Errors and debugging

Sourceval traceln : ?__POS__:(string * int * int * int) -> ('a, Format.formatter, unit, unit) format4 -> 'a

traceln fmt outputs a debug message (typically to stderr).

Trace messages are printed by default and do not require logging to be configured first. The message is printed with a newline, and is flushed automatically. traceln is intended for quick debugging rather than for production code.

Unlike most Eio operations, traceln will never switch to another fiber; if the OS is not ready to accept the message then the whole domain waits.

It is safe to call traceln from multiple domains at the same time. Each line will be written atomically.

Examples:

  traceln "x = %d" x;
  traceln "x = %d" x ~__POS__;   (* With location information *)
  • parameter __POS__

    Display __POS__ as the location of the traceln call.

Sourcemodule Exn : sig ... end

Eio exceptions.

Sourceexception Io of Exn.err * Exn.context
Sourcemodule Debug : sig ... end

Control over debugging.

Cross-platform OS API

The general pattern here is that each type of resource has a set of functions for using it, plus a provider (Pi) module to allow defining your own implementations.

The system resources are available from the environment argument provided by your event loop (e.g. Eio_main.run).

Sourcemodule Resource : sig ... end

Defines the base resource type.

Byte streams

Sourcemodule Flow : sig ... end

A flow can be used to read or write bytes.

Sourcemodule Buf_read : sig ... end

Buffered input and parsing.

Sourcemodule Buf_write : sig ... end

Buffered output and formatting.

Networking

Sourcemodule Net : sig ... end

Network sockets and addresses.

File-systems

Sourcemodule Path : sig ... end

Accessing paths on a file-system.

Sourcemodule File : sig ... end

Operations on open files.

Sourcemodule Fs : sig ... end

File-system types.

Processes

Sourcemodule Process : sig ... end

Managing child processes.

Time

Sourcemodule Time : sig ... end

Clocks, time, sleeping and timeouts.

Main env

Sourcemodule Stdenv : sig ... end

The standard environment of a process.

Provider API for OS schedulers

Sourcemodule Private : sig ... end

API for use by the scheduler implementation.