NAME
        thread - system thread management

DESCRIPTION
        thread provides thread management for the Monolith kernel.  In addition to a few functions, thread also provides a table of predefined signals(2), not to be confused with the signals returned from computer.pullSignal(2).

SIGNALS
        thread_died(pid:number)
                Queued on the death of a thread.

        thread_errored(pid:number, reason:string)
                Queued when a thread errors.

        ipc(from:number, ...)
                This signal is thread-local, and sent on IPC communication.

        signal(from:number, signal:number)
                This signal is thread-local. Sent on signal reception.

METHODS
        spawn(func:function, name:string[, handler:function[, env:table]]): number or nil, string
                Spawns a thread from function func named name.  If handler is specified, it will be called if the thread errors.  env may be used to predefine environment variables.

        threads(): table
                Returns a table of running PIDs.

        info([pid:number]): table or nil, string
                Returns a table of information about the specified thread (defaults to the current thread), or nil and an error message.

                Information tables are formatted as such:

                    {
                      name = string,
                      owner = number,
                      priority = number,
                      parent = number,
                      uptime = number,
                      started = number
                    }

                If the specified thread is the current one, the information table will have an additional field, data:
                    info.data = {
                      io = {
                        [0] = table: thread stdin,
                        [1] = table: thread stdout,
                        [2] = table: thread stderr
                      },
                      env = table: thread environment variables,
                      handles = table: opened file handles
                    }

        ipc(pid:number, ...): boolean or nil, string
                Sends an IPC event to thread pid.

        signal(pid:number, signal:number): boolean or nil, string
                Sends signal signal to thread pid.

        kill(pid:number): boolean or nil, string
                Alias for signal(pid, signals.kill)

COPYRIGHT
        Monolith Kernel Interfaces (c) 2020 Ocawesome101 under the GNU GPLv3.

SEE ALSO
        computer(2), ps(1), kill(1)