Documentation ¶
Index ¶
- Constants
- Variables
- func GoErrorDump(goError parl.GoError) (s string)
- func NewGoError(err error, errContext parl.GoErrorContext, g0 parl.Go) (goError parl.GoError)
- func NewGoGroup(ctx context.Context, onFirstFatal ...parl.GoFatalCallback) (g0 parl.GoGroup)
- func Shorts(threads []parl.ThreadData) (s string)
- func ThreadLogger(goGen parl.GoGen, logFn ...func(format string, a ...interface{})) (wg *sync.WaitGroup)
- type Go
- func (g0 *Go) AddError(err error)
- func (g0 *Go) Creator() (threadID parl.ThreadID, createLocation *pruntime.CodeLocation)
- func (g0 *Go) Done(errp *error)
- func (gi *Go) G0ID() (id GoEntityID)
- func (g0 *Go) Go() (g00 parl.Go)
- func (g0 *Go) GoID() (threadID parl.ThreadID)
- func (g0 *Go) GoRoutine() (threadID parl.ThreadID, goFunction *pruntime.CodeLocation)
- func (g0 *Go) Register(label ...string) (g00 parl.Go)
- func (g0 *Go) String() (s string)
- func (g0 *Go) SubGo(onFirstFatal ...parl.GoFatalCallback) (subGo parl.SubGo)
- func (g0 *Go) SubGroup(onFirstFatal ...parl.GoFatalCallback) (subGroup parl.SubGroup)
- func (g0 *Go) ThreadInfo() (threadData parl.ThreadData)
- func (gi *Go) Wait()
- type GoEntityID
- type GoError
- func (ge *GoError) Err() (err error)
- func (ge *GoError) ErrContext() (errContext parl.GoErrorContext)
- func (ge *GoError) Error() (message string)
- func (ge *GoError) Go() (g0 parl.Go)
- func (ge *GoError) IsFatal() (isThreadExit bool)
- func (ge *GoError) IsThreadExit() (isThreadExit bool)
- func (ge *GoError) String() (s string)
- func (ge *GoError) Time() (when time.Time)
- type GoGroup
- func (g0 *GoGroup) Add(goEntityID GoEntityID, threadData *ThreadData)
- func (cc *GoGroup) Cancel()
- func (g0 *GoGroup) CascadeEnableTermination(delta int)
- func (g0 *GoGroup) Ch() (ch <-chan parl.GoError)
- func (g0 *GoGroup) ConsumeError(goError parl.GoError)
- func (cc *GoGroup) Context() (ctx context.Context)
- func (g0 *GoGroup) EnableTermination(allowTermination bool)
- func (g0 *GoGroup) FirstFatal() (firstFatal *parl.OnceWaiterRO)
- func (g0 *GoGroup) FromGoGo() (g1 parl.Go)
- func (g0 *GoGroup) FromGoSubGo(onFirstFatal ...parl.GoFatalCallback) (g1 parl.SubGo)
- func (g0 *GoGroup) FromGoSubGroup(onFirstFatal ...parl.GoFatalCallback) (g1 parl.SubGroup)
- func (gi *GoGroup) G0ID() (id GoEntityID)
- func (g0 *GoGroup) Go() (g1 parl.Go)
- func (g0 *GoGroup) GoDone(thread parl.Go, err error)
- func (g0 *GoGroup) IsEnableTermination() (mayTerminate bool)
- func (g0 *GoGroup) NamedThreads() (threads []parl.ThreadData)
- func (g0 *GoGroup) SetDebug(debug parl.GoDebug)
- func (g0 *GoGroup) String() (s string)
- func (g0 *GoGroup) SubGo(onFirstFatal ...parl.GoFatalCallback) (g1 parl.SubGo)
- func (g0 *GoGroup) SubGroup(onFirstFatal ...parl.GoFatalCallback) (g1 parl.SubGroup)
- func (g0 *GoGroup) Threads() (threads []parl.ThreadData)
- func (g0 *GoGroup) ThreadsInternal() (orderedMap pmaps.KeyOrderedMap[GoEntityID, parl.ThreadData])
- func (g0 *GoGroup) UpdateThread(goEntityID GoEntityID, threadData *ThreadData)
- func (gi *GoGroup) Wait()
- type ThreadData
- func (td *ThreadData) Create() (createLocation *pruntime.CodeLocation)
- func (td *ThreadData) Func() (funcLocation *pruntime.CodeLocation)
- func (td *ThreadData) Get() (threadID parl.ThreadID, createLocation pruntime.CodeLocation, ...)
- func (t *ThreadData) LabeledString() (s string)
- func (td *ThreadData) Name() (label string)
- func (td *ThreadData) SetCreator(cl *pruntime.CodeLocation)
- func (td *ThreadData) Short() (s string)
- func (t *ThreadData) String() (s string)
- func (td *ThreadData) ThreadID() (threadID parl.ThreadID)
- func (td *ThreadData) Update(threadID parl.ThreadID, createInvocation, goFunction *pruntime.CodeLocation, ...)
- type ThreadSafeThreadData
- func (tw *ThreadSafeThreadData) Get() (thread *ThreadData)
- func (tw *ThreadSafeThreadData) HaveThreadID() (haveThreadID bool)
- func (tw *ThreadSafeThreadData) SetCreator(cl *pruntime.CodeLocation)
- func (tw *ThreadSafeThreadData) ThreadID() (threadID parl.ThreadID)
- func (tw *ThreadSafeThreadData) Update(threadID parl.ThreadID, createInvocation *pruntime.CodeLocation, ...)
Constants ¶
const ( ThreadDataEmpty = "[empty]" ThreadDataNil = "threadData:nil" )
Variables ¶
var GoEntityIDs parl.UniqueIDTypedUint64[GoEntityID]
GoEntityIDs is a generator for Go Object IDs
var GoGroupFactory parl.GoFactory = &goGroupFactory{}
Functions ¶
func GoErrorDump ¶ added in v0.4.82
GoErrorDump prints everything about parl.GoError
- parl.GoError: type: *g0.GoError
- err: pnet.InterfaceAddrs netInterface.Addrs route ip+net: invalid network interface at pnet.InterfaceAddrs()-interface.go:30
- t: 2023-05-10 15:53:07.885969000-07:00
- errContext: GeLocalChan
- goroutine: 72_func:g5.(*Netlink).streamReaderThread()-netlink.go:156_cre:g5.(*Netlink).ReaderThread()-netlink.go:79
func NewGoError ¶
NewGoError creates a GoError based on an error
func NewGoGroup ¶ added in v0.4.19
NewGoGroup returns a stand-alone thread-group with its own error channel. Thread-safe.
- ctx is not canceled by the thread-group
- ctx may initiate thread-group Cancel
- a stand-alone GoGroup thread-group has goGroupParent nil
- non-fatal and fatal errors from the thread-group’s threads are sent on the GoGroup’s error channel
- the GoGroup processes Go invocations and thread-exits from its own threads and the threads of its subordinate thread-groups wait-group and that of its parent
- cancel of the GoGroup’s context signals termination to its own threads and all threads of its subordinate thread-groups
- the GoGroup’s context is canceled when its provided parent context is canceled or any of its threads invoke the GoGroup’s Cancel method
- the GoGroup terminates when its error channel closes from all threads in its own thread-group and that of any subordinate thread-groups have exited.
func Shorts ¶ added in v0.4.43
func Shorts(threads []parl.ThreadData) (s string)
Shorts retruns a string of Short descriptions of all threads in the slice
- string is never empty
func ThreadLogger ¶ added in v0.4.29
func ThreadLogger(goGen parl.GoGen, logFn ...func(format string, a ...interface{})) ( wg *sync.WaitGroup)
ThreadLogger waits for a GoGroup, SubGo or SubGroup to terminate while printing information on threads that have yet to exit every second.
- invoke ThreadLogger after goGroup.Cancel and ThreadLogger will list information on goroutines that has yet to exit
- goGen is the thread group and is a parl.GoGroup SubGo or SubGroup
- — goGen should have SetDebug(parl.AggregateThread) causing it to aggregate information on live threads
- logFn is an optional logging function, default parl.Log to stderr
- ThreadLogger returns pointer to sync.WaitGroup so it can be waited upon
- —
- Because the GoGroup owner needs to continue consuming the GoGroup’s error channel, ThreadLogger has built-in threading
- the returned sync.WaitGroup pointer should be used to ensure main does not exit prematurely. The WaitGroup ends when the GoGroup ends and ThreadLogger ceases output
Usage:
main() { var goGroup = g0.NewGoGroup(context.Background()) defer goGroup.Wait() goGroup.SetDebug(parl.AggregateThread) defer func() { g0.ThreadLogger(goGroup).Wait() }() defer goGroup.Cancel()
Types ¶
type Go ¶ added in v0.4.21
type Go struct {
// contains filtered or unexported fields
}
Go supports a goroutine executing part of a thread-group. Thread-safe.
- Register allows to name the thread and collects information on the new thread
- AddError processes non-fatal errors
- Done handles thread termination and fatal errors and is deferrable. The Go thread terminates on Done invocation.
- Go creates a sibling thread object to be provided in a go statement
- SubGo creates a subordinate thread-group managed by the parent thread group. The SubGo can be independently terminated or terminated prior to thread exit.
- SubGroup creates a subordinate thread-group with its own error channel. Fatal-error thread-exits in SubGroup can be recovered locally in that thread-group
func (*Go) Creator ¶ added in v0.4.92
func (g0 *Go) Creator() (threadID parl.ThreadID, createLocation *pruntime.CodeLocation)
func (*Go) G0ID ¶ added in v0.4.29
func (gi *Go) G0ID() (id GoEntityID)
G0ID returns GoEntityID, an internal unique idntifier
func (*Go) GoRoutine ¶ added in v0.4.92
func (g0 *Go) GoRoutine() (threadID parl.ThreadID, goFunction *pruntime.CodeLocation)
func (*Go) SubGo ¶ added in v0.4.21
func (g0 *Go) SubGo(onFirstFatal ...parl.GoFatalCallback) (subGo parl.SubGo)
func (*Go) SubGroup ¶ added in v0.4.29
func (g0 *Go) SubGroup(onFirstFatal ...parl.GoFatalCallback) (subGroup parl.SubGroup)
func (*Go) ThreadInfo ¶ added in v0.4.29
func (g0 *Go) ThreadInfo() (threadData parl.ThreadData)
type GoEntityID ¶ added in v0.4.29
type GoEntityID uint64
GoEntityID is a unique named type for Go objects
- GoEntityID is required becaue for Go objects, the thread ID is not available prior to the go statement and GoGroups do not have any other unique ID
- GoEntityID is suitable as a map key
- GoEntityID uniquely identifies any Go-thread GoGroup, SubGo or SubGroup
func (GoEntityID) String ¶ added in v0.4.31
func (gi GoEntityID) String() (s string)
type GoError ¶ added in v0.4.29
type GoError struct {
// contains filtered or unexported fields
}
GoError is a wrapper around an error associating it with a Go goroutine and the situation in which this error occurred
func (*GoError) ErrContext ¶ added in v0.4.29
func (ge *GoError) ErrContext() (errContext parl.GoErrorContext)
func (*GoError) Error ¶ added in v0.4.29
Error returns a human-readable error message making GoError implement error
- for nil errors, empty string is returned
func (*GoError) IsThreadExit ¶ added in v0.4.29
type GoGroup ¶ added in v0.4.19
type GoGroup struct {
// contains filtered or unexported fields
}
GoGroup is a Go thread-group. Thread-safe.
- GoGroup has its own error channel and waitgroup and no parent thread-group.
- thread exits are processed by G1Done and the g1WaitGroup
- the thread-group terminates when its erropr channel closes
- non-fatal erors are processed by ConsumeError and the error channel
- new Go threads are handled by the g1WaitGroup
- SubGroup creates a subordinate thread-group using this threadgroup’s error channel
func (*GoGroup) Add ¶ added in v0.4.19
func (g0 *GoGroup) Add(goEntityID GoEntityID, threadData *ThreadData)
Add processes a thread from this or a subordinate thread-group
func (*GoGroup) Cancel ¶ added in v0.4.28
func (cc *GoGroup) Cancel()
Cancel signals shutdown to all threads of a thread-group.
func (*GoGroup) CascadeEnableTermination ¶ added in v0.4.69
CascadeEnableTermination manipulates wait groups of this goGroup and those of its parents to allow or prevent termination
func (*GoGroup) ConsumeError ¶ added in v0.4.29
ConsumeError receives non-fatal errors from a Go thread. Go.AddError delegates to this method
func (*GoGroup) Context ¶ added in v0.4.28
Context returns the context of this cancelAndContext.
- Context is used to detect cancel using the receive channel Context.Done.
- Context cancellation has happened when Context.Err is non-nil.
func (*GoGroup) EnableTermination ¶ added in v0.4.43
func (*GoGroup) FirstFatal ¶ added in v0.4.29
func (g0 *GoGroup) FirstFatal() (firstFatal *parl.OnceWaiterRO)
func (*GoGroup) FromGoSubGo ¶ added in v0.4.92
func (g0 *GoGroup) FromGoSubGo(onFirstFatal ...parl.GoFatalCallback) (g1 parl.SubGo)
func (*GoGroup) FromGoSubGroup ¶ added in v0.4.92
func (g0 *GoGroup) FromGoSubGroup(onFirstFatal ...parl.GoFatalCallback) (g1 parl.SubGroup)
func (*GoGroup) G0ID ¶ added in v0.4.29
func (gi *GoGroup) G0ID() (id GoEntityID)
G0ID returns GoEntityID, an internal unique idntifier
func (*GoGroup) Go ¶ added in v0.4.29
Go returns a parl.Go thread-features object
- Go is invoked by a g0-package consumer
- the Go return value is to be used as a function argument in a go-statement function-call launching a goroutine thread
func (*GoGroup) GoDone ¶ added in v0.4.29
Done receives thread exits from threads in subordinate thread-groups
func (*GoGroup) IsEnableTermination ¶ added in v0.4.43
func (*GoGroup) NamedThreads ¶ added in v0.4.43
func (g0 *GoGroup) NamedThreads() (threads []parl.ThreadData)
func (*GoGroup) String ¶ added in v0.4.20
g1Group#3threads:1(1)g0.TestNewG1Group-g1-group_test.go:60
func (*GoGroup) SubGo ¶ added in v0.4.29
func (g0 *GoGroup) SubGo(onFirstFatal ...parl.GoFatalCallback) (g1 parl.SubGo)
newSubGo returns a subordinate thread-group witthout an error channel. Thread-safe.
- a SubGo has goGroupParent non-nil and isSubGo true
- the SubGo thread’s fatal and non-fatal errors are forwarded to its parent
- SubGo has FirstFatal mechanic but no error channel of its own.
- the SubGo’s Go invocations and thread-exits are processed by the SubGo’s wait-group and the thread-group of its parent
- cancel of the SubGo’s context signals termination to its own threads and all threads of its subordinate thread-groups
- the SubGo’s context is canceled when its parent’s context is canceled or any of its threads invoke the SubGo’s Cancel method
- the SubGo thread-group terminates when all threads in its own thread-group and that of any subordinate thread-groups have exited.
func (*GoGroup) SubGroup ¶ added in v0.4.29
func (g0 *GoGroup) SubGroup(onFirstFatal ...parl.GoFatalCallback) (g1 parl.SubGroup)
newSubGroup returns a subordinate thread-group with an error channel handling fatal errors only. Thread-safe.
- a SubGroup has goGroupParent non-nil and isSubGo false
- fatal errors from the SubGroup’s threads are sent on its own error channel
- non-fatal errors from the SubGroup’s threads are forwarded to the parent
- the SubGroup’s Go invocations and thread-exits are processed in the SubGroup’s wait-group and that of its parent
- cancel of the SubGroup’s context signals termination to its own threads and all threads of its subordinate thread-groups
- the SubGroup’s context is canceled when its parent’s context is canceled or any of its threads invoke the SubGroup’s Cancel method
- SubGroup thread-group terminates when its error channel closes after all of its threads and threads of its subordinate thread-groups have exited.
func (*GoGroup) Threads ¶ added in v0.4.43
func (g0 *GoGroup) Threads() (threads []parl.ThreadData)
func (*GoGroup) ThreadsInternal ¶ added in v0.4.93
func (g0 *GoGroup) ThreadsInternal() (orderedMap pmaps.KeyOrderedMap[GoEntityID, parl.ThreadData])
func (*GoGroup) UpdateThread ¶ added in v0.4.29
func (g0 *GoGroup) UpdateThread(goEntityID GoEntityID, threadData *ThreadData)
type ThreadData ¶ added in v0.4.29
type ThreadData struct {
// contains filtered or unexported fields
}
ThreadData contains identifiable information about a running thread.
- ThreadData does not have initialization
func (*ThreadData) Create ¶ added in v0.4.43
func (td *ThreadData) Create() (createLocation *pruntime.CodeLocation)
func (*ThreadData) Func ¶ added in v0.4.43
func (td *ThreadData) Func() (funcLocation *pruntime.CodeLocation)
func (*ThreadData) Get ¶ added in v0.4.29
func (td *ThreadData) Get() (threadID parl.ThreadID, createLocation pruntime.CodeLocation, funcLocation pruntime.CodeLocation, label string)
func (*ThreadData) LabeledString ¶ added in v0.4.92
func (t *ThreadData) LabeledString() (s string)
func (*ThreadData) Name ¶ added in v0.4.43
func (td *ThreadData) Name() (label string)
func (*ThreadData) SetCreator ¶ added in v0.4.29
func (td *ThreadData) SetCreator(cl *pruntime.CodeLocation)
SetCreator gets preliminary Go identifier: the line invoking Go()
func (*ThreadData) Short ¶ added in v0.4.43
func (td *ThreadData) Short() (s string)
"myThreadName:4"
func (*ThreadData) String ¶ added in v0.4.43
func (t *ThreadData) String() (s string)
"myThreadName:4_func:testing.tRunner()-testing.go:1446_cre:testing.(*T).Run()-testing.go:1493"
func (*ThreadData) ThreadID ¶ added in v0.4.29
func (td *ThreadData) ThreadID() (threadID parl.ThreadID)
threadID is the ID of the running thread
func (*ThreadData) Update ¶ added in v0.4.29
func (td *ThreadData) Update( threadID parl.ThreadID, createInvocation, goFunction *pruntime.CodeLocation, label string)
Update populates this object from a stack trace.
type ThreadSafeThreadData ¶ added in v0.4.37
type ThreadSafeThreadData struct {
// contains filtered or unexported fields
}
ThreadSafeThreadData controls access to a ThreadData object making it thread-safe.
- ThreadSafeThreadData does not have initialization
- haveThreadID indicates whether data is present
func (*ThreadSafeThreadData) Get ¶ added in v0.4.37
func (tw *ThreadSafeThreadData) Get() (thread *ThreadData)
Get returns a clone of the wrapped ThreadData object.
func (*ThreadSafeThreadData) HaveThreadID ¶ added in v0.4.37
func (tw *ThreadSafeThreadData) HaveThreadID() (haveThreadID bool)
HaveThreadID indicates whether Update has been invoked on this ThreadDataWrap object.
func (*ThreadSafeThreadData) SetCreator ¶ added in v0.4.37
func (tw *ThreadSafeThreadData) SetCreator(cl *pruntime.CodeLocation)
SetCreator gets preliminary Go identifier: the line invoking Go().
func (*ThreadSafeThreadData) ThreadID ¶ added in v0.4.37
func (tw *ThreadSafeThreadData) ThreadID() (threadID parl.ThreadID)
ThreadID returns the thread id of the running thread or zero if thread ID is missing.
func (*ThreadSafeThreadData) Update ¶ added in v0.4.37
func (tw *ThreadSafeThreadData) Update( threadID parl.ThreadID, createInvocation *pruntime.CodeLocation, goFunction *pruntime.CodeLocation, label string, )
Update populates the wrapped ThreadData from the stack trace.