The moira Reference Manual

Next: , Previous: , Up: (dir)   [Contents][Index]

The moira Reference Manual

This is the moira Reference Manual, generated automatically by Declt version 4.0 beta 2 "William Riker" on Wed Jun 15 05:22:05 2022 GMT+0.

Table of Contents


1 Introduction

Μοῖρα

Moira is a simple (but not quite trivial) library for monitoring and, if necessary, restarting long-running threads. In principle, it is like an in-Lisp process supervisor.

To start the monitor, you call start-monitor:

(moira:start-monitor)

Once the monitor is started, you can spawn new threads:

(moira:spawn "Background worker"
  ...))

Which is syntactic sugar for

(moira:spawn-thread
 (lambda () ...)
 :name "Background worker")

If the thread created by spawn-thread should crash, or otherwise exit abnormally, Moira will step in and restart the thread.

You can stop monitoring with stop-monitor

(moira:stop-monitor)

Although this will not affect the spawned threads.

On Linux only, Moira also tracks the thread ID (value of gettid) of the Lisp threads it launches. This can be useful for tracking the resource usage of individual thr


2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 moira

Monitor and restart background threads.

Author

Paul M. Rodriguez <pmr@ruricolist.com>

License

MIT

Dependencies
  • alexandria (system).
  • serapeum (system).
  • trivial-features (system).
  • bordeaux-threads (system).
  • trivial-garbage (system).
  • osicat (system).
Source

moira.asd.

Child Components

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp   [Contents][Index]

3.1.1 moira/moira.asd

Source

moira.asd.

Parent Component

moira (system).

ASDF Systems

moira.


Next: , Previous: , Up: Lisp   [Contents][Index]

3.1.2 moira/package.lisp

Source

moira.asd.

Parent Component

moira (system).

Packages

moira.


3.1.3 moira/types.lisp

Dependency

package.lisp (file).

Source

moira.asd.

Parent Component

moira (system).

Internals

Next: , Previous: , Up: Lisp   [Contents][Index]

3.1.4 moira/thread-ids.lisp

Dependency

package.lisp (file).

Source

moira.asd.

Parent Component

moira (system).

Public Interface
Internals

3.1.5 moira/moira.lisp

Dependencies
Source

moira.asd.

Parent Component

moira (system).

Public Interface
Internals

Next: , Previous: , Up: Lisp   [Contents][Index]

3.1.6 moira/monitor.lisp

Dependencies
Source

moira.asd.

Parent Component

moira (system).

Public Interface
Internals

Previous: , Up: Lisp   [Contents][Index]

3.1.7 moira/spawn.lisp

Dependencies
Source

moira.asd.

Parent Component

moira (system).

Public Interface
Internals

make-thread-and-wait (function).


4 Packages

Packages are listed by definition order.


Previous: , Up: Packages   [Contents][Index]

4.1 moira

Source

package.lisp.

Use List
  • alexandria.
  • common-lisp.
  • serapeum.
Public Interface
Internals

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Public Interface


5.1.1 Macros

Macro: spawn (&body body)

Like (spawn-thread (lambda () ...)).
If the first form in BODY is a string, that string is used as the name of the thread.

Package

moira.

Source

spawn.lisp.


5.1.2 Ordinary functions

Function: list-monitored-threads ()
Package

moira.

Source

moira.lisp.

Function: make-thread-saving-id (thunk &rest args)

Like ‘bt:make-thread’, but save the id of the resulting thread so it can be retrieved later with ‘moira:thread-id’.

Using ‘moira:make-thread-saving-id’ lets you start a thread that is not monitored, but does have its ID tracked.

Package

moira.

Source

spawn.lisp.

Function: save-current-thread-id ()
Package

moira.

Source

thread-ids.lisp.

Function: spawn-thread (thunk &key name)

Run THUNK as a thread, automatically respawning if the thread exits abnormally.

Package

moira.

Source

spawn.lisp.

Function: start-monitor ()
Package

moira.

Source

monitor.lisp.

Function: stop-monitor ()
Package

moira.

Source

monitor.lisp.

Function: thread-id (thread)
Package

moira.

Source

thread-ids.lisp.


5.1.3 Standalone methods

Method: initialize-instance :after ((self monitored-thread) &key)
Source

moira.lisp.

Method: print-object ((self monitored-thread) stream)
Source

moira.lisp.


5.2 Internals


Next: , Previous: , Up: Internals   [Contents][Index]

5.2.1 Special variables

Special Variable: *monitor*
Package

moira.

Source

monitor.lisp.

Special Variable: *monitored-threads*
Package

moira.

Source

moira.lisp.

Special Variable: *thread-ids*
Package

moira.

Source

thread-ids.lisp.


5.2.2 Symbol macros

Symbol Macro: monitor-flag
Package

moira.

Source

monitor.lisp.


5.2.3 Ordinary functions

Function: clear-monitored-threads ()
Package

moira.

Source

moira.lisp.

Function: id-thread (id)
Package

moira.

Source

thread-ids.lisp.

Function: make-thread-and-wait (thunk &rest args)

Like ‘make-thread-saving-id’, but wait to return until the thread is actually running.

Package

moira.

Source

spawn.lisp.

Function: monitor-loop ()
Package

moira.

Source

monitor.lisp.

Function: thread-alive-p (x)
Package

moira.

Source

types.lisp.


Next: , Previous: , Up: Internals   [Contents][Index]

5.2.4 Generic functions

Generic Function: ensure-alive (self)
Package

moira.

Methods
Method: ensure-alive ((self monitored-thread))
Source

moira.lisp.

Generic Reader: monitored-thread.donep (object)
Package

moira.

Methods
Reader Method: monitored-thread.donep ((monitored-thread monitored-thread))

automatically generated reader method

Source

moira.lisp.

Target Slot

done.

Generic Reader: monitored-thread.name (object)
Package

moira.

Methods
Reader Method: monitored-thread.name ((monitored-thread monitored-thread))

automatically generated reader method

Source

moira.lisp.

Target Slot

name.

Generic Reader: monitored-thread.thread (object)
Package

moira.

Methods
Reader Method: monitored-thread.thread ((monitored-thread monitored-thread))

automatically generated reader method

Source

moira.lisp.

Target Slot

thread.

Generic Reader: monitored-thread.thunk (object)
Package

moira.

Methods
Reader Method: monitored-thread.thunk ((monitored-thread monitored-thread))

automatically generated reader method

Source

moira.lisp.

Target Slot

thunk.

Generic Function: start (self)
Package

moira.

Methods
Method: start ((self monitored-thread))
Source

moira.lisp.

Generic Function: stop (self)
Package

moira.

Methods
Method: stop ((self monitored-thread))
Source

moira.lisp.


Next: , Previous: , Up: Internals   [Contents][Index]

5.2.5 Classes

Class: monitored-thread
Package

moira.

Source

moira.lisp.

Direct superclasses

synchronized.

Direct methods
Direct slots
Slot: thread
Type

moira::a-thread

Readers

monitored-thread.thread.

Writers

This slot is read-only.

Slot: done
Type

boolean

Readers

monitored-thread.donep.

Writers

This slot is read-only.

Slot: thunk
Type

function

Initargs

:thunk

Readers

monitored-thread.thunk.

Writers

This slot is read-only.

Slot: name
Type

string

Initargs

:name

Readers

monitored-thread.name.

Writers

This slot is read-only.


Previous: , Up: Internals   [Contents][Index]

5.2.6 Types

Type: a-thread ()
Package

moira.

Source

types.lisp.

Type: dead-thread ()
Package

moira.

Source

types.lisp.

Type: live-thread ()
Package

moira.

Source

types.lisp.

Type: no-thread ()
Package

moira.

Source

types.lisp.

Type: thread ()
Package

moira.

Source

types.lisp.


Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts


Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   C   E   F   G   I   L   M   P   S   T  
Index Entry  Section

C
clear-monitored-threads: Private ordinary functions

E
ensure-alive: Private generic functions
ensure-alive: Private generic functions

F
Function, clear-monitored-threads: Private ordinary functions
Function, id-thread: Private ordinary functions
Function, list-monitored-threads: Public ordinary functions
Function, make-thread-and-wait: Private ordinary functions
Function, make-thread-saving-id: Public ordinary functions
Function, monitor-loop: Private ordinary functions
Function, save-current-thread-id: Public ordinary functions
Function, spawn-thread: Public ordinary functions
Function, start-monitor: Public ordinary functions
Function, stop-monitor: Public ordinary functions
Function, thread-alive-p: Private ordinary functions
Function, thread-id: Public ordinary functions

G
Generic Function, ensure-alive: Private generic functions
Generic Function, monitored-thread.donep: Private generic functions
Generic Function, monitored-thread.name: Private generic functions
Generic Function, monitored-thread.thread: Private generic functions
Generic Function, monitored-thread.thunk: Private generic functions
Generic Function, start: Private generic functions
Generic Function, stop: Private generic functions

I
id-thread: Private ordinary functions
initialize-instance: Public standalone methods

L
list-monitored-threads: Public ordinary functions

M
Macro, spawn: Public macros
make-thread-and-wait: Private ordinary functions
make-thread-saving-id: Public ordinary functions
Method, ensure-alive: Private generic functions
Method, initialize-instance: Public standalone methods
Method, monitored-thread.donep: Private generic functions
Method, monitored-thread.name: Private generic functions
Method, monitored-thread.thread: Private generic functions
Method, monitored-thread.thunk: Private generic functions
Method, print-object: Public standalone methods
Method, start: Private generic functions
Method, stop: Private generic functions
monitor-loop: Private ordinary functions
monitored-thread.donep: Private generic functions
monitored-thread.donep: Private generic functions
monitored-thread.name: Private generic functions
monitored-thread.name: Private generic functions
monitored-thread.thread: Private generic functions
monitored-thread.thread: Private generic functions
monitored-thread.thunk: Private generic functions
monitored-thread.thunk: Private generic functions

P
print-object: Public standalone methods

S
save-current-thread-id: Public ordinary functions
spawn: Public macros
spawn-thread: Public ordinary functions
start: Private generic functions
start: Private generic functions
start-monitor: Public ordinary functions
stop: Private generic functions
stop: Private generic functions
stop-monitor: Public ordinary functions

T
thread-alive-p: Private ordinary functions
thread-id: Public ordinary functions

Jump to:   C   E   F   G   I   L   M   P   S   T