Documentation
¶
Overview ¶
Package threads provides SRFI-18 multithreading primitives.
Threads ¶
- make-thread, thread?
- thread-name, thread-specific, thread-specific-set!
- thread-start!, thread-yield!, thread-sleep!
- thread-terminate!, thread-join!
- current-thread
Mutexes ¶
- make-mutex, mutex?
- mutex-name, mutex-specific, mutex-specific-set!
- mutex-state
- mutex-lock!, mutex-unlock!
Condition Variables ¶
- make-condition-variable, condition-variable?
- condition-variable-name
- condition-variable-specific, condition-variable-specific-set!
- condition-variable-signal!, condition-variable-broadcast!
Time ¶
- current-time, time?, time->seconds, seconds->time
Exceptions ¶
- join-timeout-exception?, abandoned-mutex-exception?
- terminated-thread-exception?, uncaught-exception?
- uncaught-exception-reason
Use Extension or AddToRegistry to register all primitives.
Package threads provides SRFI-18 threading primitives.
Index ¶
- Variables
- func PrimCurrentThread(mc machine.CallContext) error
- func PrimCurrentTime(mc machine.CallContext) error
- func PrimMakeConditionVariable(mc machine.CallContext) error
- func PrimMakeMutex(mc machine.CallContext) error
- func PrimMakeThread(cc machine.CallContext) error
- func PrimMutexLock(mc machine.CallContext) error
- func PrimMutexUnlock(mc machine.CallContext) error
- func PrimSecondsToTime(mc machine.CallContext) error
- func PrimThreadJoin(mc machine.CallContext) error
- func PrimThreadSleep(mc machine.CallContext) error
- func PrimThreadStart(mc machine.CallContext) error
- func PrimThreadYield(mc machine.CallContext) error
Constants ¶
This section is empty.
Variables ¶
var AddToRegistry = Builder.AddToRegistry
AddToRegistry registers all threading primitives.
var Builder = registry.NewRegistryBuilder(addThreads, addMutexes, addConditionVariables, addTime)
Builder aggregates all threading registration functions.
var Extension = registry.NewDescribedExtension("threads", "Concurrency: SRFI-18 threads, mutexes, condition variables, channels.", AddToRegistry)
Extension is the threads extension.
var PrimConditionVariableBroadcast = helpers.MakeUnarySideEffect(werr.ErrNotAConditionVariable, "condition-variable-broadcast!", func(cv *values.ConditionVariable) {
cv.Broadcast()
})
PrimConditionVariableBroadcast signals all waiting threads (condition-variable-broadcast! cv) -> void
var PrimConditionVariableName = helpers.MakeUnaryAccessor(werr.ErrNotAConditionVariable, "condition-variable-name", func(cv *values.ConditionVariable) values.Value { return values.NewString(cv.Name()) })
PrimConditionVariableName returns the condition variable's name (condition-variable-name cv) -> string or symbol
var PrimConditionVariableQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(*values.ConditionVariable) return ok })
PrimConditionVariableQ tests if an object is a condition variable (condition-variable? obj) -> boolean
var PrimConditionVariableSignal = helpers.MakeUnarySideEffect(werr.ErrNotAConditionVariable, "condition-variable-signal!", func(cv *values.ConditionVariable) {
cv.Signal()
})
PrimConditionVariableSignal signals one waiting thread (condition-variable-signal! cv) -> void
var PrimConditionVariableSpecific = helpers.MakeUnaryAccessor(werr.ErrNotAConditionVariable, "condition-variable-specific", func(cv *values.ConditionVariable) values.Value { return values.ValueOrVoid(cv.Specific()) })
PrimConditionVariableSpecific returns the condition variable's specific field (condition-variable-specific cv) -> value
var PrimConditionVariableSpecificSet = helpers.MakeBinarySetter(werr.ErrNotAConditionVariable, "condition-variable-specific-set!", func(cv *values.ConditionVariable, val values.Value) {
cv.SetSpecific(val)
})
PrimConditionVariableSpecificSet sets the condition variable's specific field (condition-variable-specific-set! cv obj) -> void
var PrimMutexName = helpers.MakeUnaryAccessor(werr.ErrNotAMutex, "mutex-name", func(mutex *values.Mutex) values.Value { return values.NewString(mutex.Name()) })
PrimMutexName returns the mutex's name (mutex-name mutex) -> string or symbol
var PrimMutexQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(*values.Mutex) return ok })
PrimMutexQ tests if an object is a mutex (mutex? obj) -> boolean
var PrimMutexSpecific = helpers.MakeUnaryAccessor(werr.ErrNotAMutex, "mutex-specific", func(mutex *values.Mutex) values.Value { return values.ValueOrVoid(mutex.Specific()) })
PrimMutexSpecific returns the mutex's specific field (mutex-specific mutex) -> value
var PrimMutexSpecificSet = helpers.MakeBinarySetter(werr.ErrNotAMutex, "mutex-specific-set!", func(mutex *values.Mutex, val values.Value) {
mutex.SetSpecific(val)
})
PrimMutexSpecificSet sets the mutex's specific field (mutex-specific-set! mutex obj) -> void
var PrimMutexState = helpers.MakeUnaryAccessor(werr.ErrNotAMutex, "mutex-state", func(mutex *values.Mutex) values.Value {
return mutex.StateValue()
})
PrimMutexState returns the mutex's state (mutex-state mutex) -> symbol or thread Returns: 'not-owned, 'abandoned, or the owner thread
var PrimThreadName = helpers.MakeUnaryAccessor(werr.ErrNotAThread, "thread-name", func(thread *values.Thread) values.Value { return values.NewString(thread.Name()) })
PrimThreadName returns the thread's name (thread-name thread) -> string or symbol
var PrimThreadQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(*values.Thread) return ok })
PrimThreadQ tests if an object is a thread (thread? obj) -> boolean
var PrimThreadSpecific = helpers.MakeUnaryAccessor(werr.ErrNotAThread, "thread-specific", func(thread *values.Thread) values.Value { return values.ValueOrVoid(thread.Specific()) })
PrimThreadSpecific returns the thread's specific field (thread-specific thread) -> value
var PrimThreadSpecificSet = helpers.MakeBinarySetter(werr.ErrNotAThread, "thread-specific-set!", func(thread *values.Thread, val values.Value) {
thread.SetSpecific(val)
})
PrimThreadSpecificSet sets the thread's specific field (thread-specific-set! thread obj) -> void
var PrimThreadTerminate = helpers.MakeUnarySideEffect(werr.ErrNotAThread, "thread-terminate!", func(thread *values.Thread) {
thread.Terminate()
})
PrimThreadTerminate forcefully terminates a thread (thread-terminate! thread) -> void
var PrimTimeQ = helpers.MakeTypePredicate(func(o values.Value) bool { _, ok := o.(*values.Time) return ok })
PrimTimeQ tests if an object is a time (time? obj) -> boolean
var PrimTimeToSeconds = helpers.MakeUnaryAccessor(werr.ErrNotATime, "time->seconds", func(t *values.Time) values.Value { return values.NewFloat(t.Seconds()) })
PrimTimeToSeconds converts a time to seconds (time->seconds time) -> number
Functions ¶
func PrimCurrentThread ¶
func PrimCurrentThread(mc machine.CallContext) error
PrimCurrentThread returns the current executing thread. Returns the thread object if running inside a thread, or the symbol 'primordial for the main goroutine. (current-thread) -> thread
func PrimCurrentTime ¶
func PrimCurrentTime(mc machine.CallContext) error
PrimCurrentTime returns the current time (current-time) -> time
func PrimMakeConditionVariable ¶
func PrimMakeConditionVariable(mc machine.CallContext) error
PrimMakeConditionVariable creates a new condition variable (make-condition-variable [name]) -> condition-variable
func PrimMakeMutex ¶
func PrimMakeMutex(mc machine.CallContext) error
PrimMakeMutex creates a new mutex (make-mutex [name]) -> mutex
func PrimMakeThread ¶
func PrimMakeThread(cc machine.CallContext) error
PrimMakeThread creates a new thread (make-thread thunk [name]) -> thread
func PrimMutexLock ¶
func PrimMutexLock(mc machine.CallContext) error
PrimMutexLock acquires the mutex (mutex-lock! mutex [timeout [thread]]) -> boolean Returns #t if acquired, #f if timeout
func PrimMutexUnlock ¶
func PrimMutexUnlock(mc machine.CallContext) error
PrimMutexUnlock releases the mutex (mutex-unlock! mutex [condition-variable [timeout]]) -> boolean
func PrimSecondsToTime ¶
func PrimSecondsToTime(mc machine.CallContext) error
PrimSecondsToTime converts seconds to a time (seconds->time x) -> time
func PrimThreadJoin ¶
func PrimThreadJoin(mc machine.CallContext) error
PrimThreadJoin waits for a thread to terminate (thread-join! thread [timeout [timeout-val]]) -> value
func PrimThreadSleep ¶
func PrimThreadSleep(mc machine.CallContext) error
PrimThreadSleep pauses execution for a time (thread-sleep! timeout) -> void timeout can be a time object or a number (seconds)
func PrimThreadStart ¶
func PrimThreadStart(mc machine.CallContext) error
PrimThreadStart starts a thread (thread-start! thread) -> thread
func PrimThreadYield ¶
func PrimThreadYield(mc machine.CallContext) error
PrimThreadYield yields execution to other threads (thread-yield!) -> void
Types ¶
This section is empty.