g0

package
v0.4.89 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2023 License: ISC Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ThreadDataEmpty = "[empty]"
	ThreadDataNil   = "threadData:nil"
)

Variables

GoEntityIDs is a generator for Go Object IDs

View Source
var GoGroupFactory parl.GoFactory = &goGroupFactory{}

Functions

func GoErrorDump added in v0.4.82

func GoErrorDump(goError parl.GoError) (s string)

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

func NewGoError(err error, errContext parl.GoErrorContext, g0 parl.Go) (goError parl.GoError)

NewGoError creates a GoError based on an error

func NewGoGroup added in v0.4.19

func NewGoGroup(ctx context.Context, onFirstFatal ...parl.GoFatalCallback) (g0 parl.GoGroup)

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 ThreadInfo added in v0.4.40

func ThreadInfo(t *ThreadData) (s string)

func ThreadLogger added in v0.4.29

func ThreadLogger(goGen parl.GoGen, wg parl.SyncDone, logFn ...func(format string, a ...interface{}))

ThreadLogger waits for a GoGroup, SubGo or SubGroup to terminate while printing information on threads that have yet to exit.

  • ThreadLogger is non-blocking and will invoke Done on wg on thread0-group termination
  • goGen is the thread group and must be a parl.GoGroup SubGo or SubGroup
  • wg is a WaitGroup allowing ThreadLogger to be waited upon
  • logFn is an optional logging function default parl.Log

Usage:

main() {
  var debugWait sync.WaitGroup
  defer debugWait.Wait()
 …
 debugWait.Add(1)
 ThreadLogger(goGroup, &debugWait)

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) AddError added in v0.4.21

func (g0 *Go) AddError(err error)

func (*Go) Done added in v0.4.21

func (g0 *Go) Done(errp *error)

Done handles thread exit. Deferrable

func (*Go) G0ID added in v0.4.29

func (gi *Go) G0ID() (id GoEntityID)

G0ID returns GoEntityID, an internal unique idntifier

func (*Go) Go added in v0.4.78

func (g0 *Go) Go() (g00 parl.Go)

func (*Go) GoID added in v0.4.48

func (g0 *Go) GoID() (threadID parl.ThreadID)

func (*Go) Register added in v0.4.21

func (g0 *Go) Register(label ...string) (g00 parl.Go)

func (*Go) String added in v0.4.29

func (g0 *Go) String() (s string)

g1ID:4:g0.(*g1WaitGroup).Go-g1-thread-group.go:63

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)

func (*Go) Wait added in v0.4.29

func (gi *Go) Wait()

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) Err added in v0.4.29

func (ge *GoError) Err() (err error)

Err returns the unbderlying error

func (*GoError) ErrContext added in v0.4.29

func (ge *GoError) ErrContext() (errContext parl.GoErrorContext)

func (*GoError) Error added in v0.4.29

func (ge *GoError) Error() (message string)

Error returns a human-readable error message making GoError implement error

  • for nil errors, empty string is returned

func (*GoError) Go added in v0.4.29

func (ge *GoError) Go() (g0 parl.Go)

func (*GoError) IsFatal added in v0.4.29

func (ge *GoError) IsFatal() (isThreadExit bool)

func (*GoError) IsThreadExit added in v0.4.29

func (ge *GoError) IsThreadExit() (isThreadExit bool)

func (*GoError) String added in v0.4.29

func (ge *GoError) String() (s string)

func (*GoError) Time added in v0.4.29

func (ge *GoError) Time() (when time.Time)

Time returns when the GoError was created

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

func (g0 *GoGroup) CascadeEnableTermination(delta int)

CascadeEnableTermination manipulates wait groups of this goGroup and those of its parents to allow or prevent termination

func (*GoGroup) Ch added in v0.4.20

func (g0 *GoGroup) Ch() (ch <-chan parl.GoError)

func (*GoGroup) ConsumeError added in v0.4.29

func (g0 *GoGroup) ConsumeError(goError parl.GoError)

ConsumeError receives non-fatal errors from a Go thread. Go.AddError delegates to this method

func (*GoGroup) Context added in v0.4.28

func (cc *GoGroup) Context() (ctx context.Context)

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 (g0 *GoGroup) EnableTermination(allowTermination bool)

func (*GoGroup) FirstFatal added in v0.4.29

func (g0 *GoGroup) FirstFatal() (firstFatal *parl.OnceWaiterRO)

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

func (g0 *GoGroup) Go() (g1 parl.Go)

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

func (g0 *GoGroup) GoDone(thread parl.Go, err error)

Done receives thread exits from threads in subordinate thread-groups

func (*GoGroup) IsEnableTermination added in v0.4.43

func (g0 *GoGroup) IsEnableTermination() (mayTerminate bool)

func (*GoGroup) NamedThreads added in v0.4.43

func (g0 *GoGroup) NamedThreads() (threads []parl.ThreadData)

func (*GoGroup) SetDebug added in v0.4.43

func (g0 *GoGroup) SetDebug(debug parl.GoDebug)

func (*GoGroup) String added in v0.4.20

func (g0 *GoGroup) String() (s string)

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) UpdateThread added in v0.4.29

func (g0 *GoGroup) UpdateThread(goEntityID GoEntityID, threadData *ThreadData)

func (*GoGroup) Wait added in v0.4.19

func (gi *GoGroup) Wait()

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) 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 (td *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(stack parl.Stack, 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(stack parl.Stack, label string)

Update populates the wrapped ThreadData from the stack trace.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL