Thread
classin packageklyn.threading
public class Thread extends Object implements Runnable
└ Thread
All Implemented Interfaces: Runnable

Native thread with cooperative pause, interruption and stop requests.

Workers cooperate explicitly with Thread.checkpoint(). No checks are injected into ordinary loops, and a request never forcibly kills a worker.

Example
def runWorker() as Void:
    while Thread.checkpoint():
        Thread.sleep(10)
worker = Thread(lambda(): runWorker())
worker.start()
worker.requestStop()
worker.join()
Properties
Modifier and Type Member Description
public static readonly property activeCount
activeCount as UInt
Returns the number of logically active threads.
public static readonly property currentThread
currentThread as Thread
Returns the current logical thread.
public readonly property id
id as ULong
Unique thread id.
public readonly property isAlive
isAlive as Boolean
Returns true between native startup and actual completion.
public readonly property isInterrupted
isInterrupted as Boolean
Returns true when interruption was requested.
public property name
name as String
Thread name.
public property priority
priority as String
Requested native scheduling priority: LOWEST, LOW, NORMAL, HIGH or HIGHEST.
public readonly property state
state as String
Current lifecycle state.
public readonly property stopRequested
stopRequested as Boolean
Returns whether cooperative stopping was requested.
Inherited Properties
propertyInherited Properties from Object: type
Constructors
Modifier and Type Member Description
public Thread Creates a thread with an auto-generated name derived from its unique id.
public Thread
Thread(name as String)
Creates a thread with the requested name.
public Thread
Thread(runnable as Runnable)
Creates a thread that executes the supplied runnable.
public Thread
Thread(runnable as Runnable, name as String)
Creates a named thread that executes the supplied runnable.
Methods
Modifier and Type Member Description
public static checkpoint
checkpoint() as Boolean
Explicit cooperation point for the current thread.
public static current
current() as Thread
Alias for currentThread.
public interrupt
interrupt() as Void
Records interruption atomically and wakes an interruptible sleep.
public join
join() as Void
Waits for completion.
public join
join(timeoutMillis as Int) as Void
Waits up to a timeout in milliseconds.
public static relinquish
relinquish() as Void
Suggests that the scheduler let another ready thread execute.
public requestStop
requestStop() as Void
Requests cooperative stopping and wakes sleep or a paused checkpoint.
public resume
resume() as Void
Withdraws the pause request and wakes a paused worker.
public override run
run() as Void
Runnable entrypoint.
public static sleep
sleep(millis as Int) as Void
Sleeps until the requested deadline, or an early stop/interruption.
public start
start() as Void
Starts the thread execution.
public stop
stop() as Void
Compatibility alias for requestStop(); never forcibly kills a worker.
public suspend
suspend() as Void
Requests a cooperative pause, acknowledged at the next checkpoint.
public override toString
toString() as String
Returns a readable thread representation.
Inherited Methods
methodInherited Methods from Object: deepCopy, fromJson, hash, toDict, toJson, toMap, toString, toXml
methodInherited Methods from Runnable: run