Idris2Doc : IO.Async.Loop.Posix

IO.Async.Loop.Posix

(source)
A pool of a fixed number of worker threads, each operating on its own
work queue.

Idle threads will try and take work packages from other threads
(work-stealing).

Each thread is responsible for scheduling and running an arbitrary number
of `Fiber`s, as well as taking care of registered timers, signal handlers,
and file polling.

Reexports

importpublic Data.Nat
importpublic IO.Async
importpublic IO.Async.Loop
importpublic IO.Async.Loop.PollH
importpublic IO.Async.Loop.SignalH
importpublic IO.Async.Loop.TimerH

Definitions

0Task : Type
Totality: total
Visibility: public export
recordPoll : Type
Totality: total
Visibility: export
Constructor: 
W : (size : Nat) ->Finsize->IORefBool->IORef (QueueTask) ->IArraysizePoll->Poller->IORefNat->Timer->Sighandler->Mutex->Condition->Poll

Projections:
.alive : Poll->IORefBool
  Reference indicating whether the pool is still alive
.cond : Poll->Condition
  Condition used for sleeping
.lock : Poll->Mutex
  Mutex used for sleeping
.me : ({rec:0} : Poll) ->Fin (size{rec:0})
  Index of the worker thread corresponding to this state
.poller : Poll->Poller
  The state used for polling file descriptors
.queue : Poll->IORef (QueueTask)
  Work queue of this worker
.signals : Poll->Sighandler
  State for the signal handler
.size : Poll->Nat
  Number of worker threads in the pool
.stealers : Poll->IORefNat
  Remaining number of stealers. To reduce contention,
not all idle workers will be allowed to steal work
at the same time
.timer : Poll->Timer
  State for schedule actions
.workers : ({rec:0} : Poll) ->IArray (size{rec:0}) Poll
  Work queues of all worker threads

Hints:
EventLoopPoll
PollHPoll
SignalHPoll
TimerHPoll
recordThreadPool : Type
  A fixed-size pool of `n` physical worker threads.

Tasks are submited to the worker threads in round-robin
fashion: A new task is submitted to the next worker in line,
restarting at the beginning when reaching the last worker.

Totality: total
Visibility: export
Constructor: 
TP : (size : Nat) ->VectsizeThreadID->ThreadID->Vect (Ssize) Poll->ThreadPool

Projections:
.ids : ({rec:0} : ThreadPool) ->Vect (size{rec:0}) ThreadID
.pollid : ThreadPool->ThreadID
.size : ThreadPool->Nat
.workers : ({rec:0} : ThreadPool) ->Vect (S (size{rec:0})) Poll
app : SubsetNatIsSucc->ListSignal->IO1Poller->AsyncPoll [] () ->IO ()
  Starts an epoll-based event loop and runs the given async
program to completion.

`n` : Number of threads to use
`sigs` : The signals to block while running the program.
These are typically the ones dealt with as part of `prog`
`prog` : The program to run

Visibility: export
asyncThreads : IO (SubsetNatIsSucc)
  Reads environment variable `IDRIS2_ASYNC_THREADS` and returns
the number of threads to use. Default: 2.

Totality: total
Visibility: export
simpleApp : {default [SIGINT] sigs : ListSignal} ->HasSIGINTsigs=>AsyncPoll [] () ->IO ()
  Simplified version of `app`.

This uses the posix-compatible `poll` call for polling files. For
a faster poller - especially when polling hundreds or thousands of
file descriptors at a time - consider using `IO.Async.Loop.Epoll.epollApp`.

We use environment variable `IDRIS2_ASYNC_THREADS` to determine the
number of threads to use (default: 2) and cancel the running program
on receiving `SIGINT`.

By default, only `SIGINT` is masked, to handle other signals
within your program, give `{sigs = [...]}` as the first
argument. One of the signals must be SIGINT, which is enforced by
the `Has SIGINT sigs` constraint.

Visibility: export