diff --git a/proc/threads.go b/proc/threads.go index 9a918fc7..c6757141 100644 --- a/proc/threads.go +++ b/proc/threads.go @@ -299,3 +299,19 @@ func (thread *Thread) GetG() (g *G, err error) { func (thread *Thread) Stopped() bool { return thread.stopped() } + +// Stops this thread from executing. Actual +// implementation is OS dependant. Look in OS +// thread file. +func (thread *Thread) Halt() (err error) { + defer func() { + if err == nil { + thread.running = false + } + }() + if thread.Stopped() { + return + } + err = thread.halt() + return +} diff --git a/proc/threads_darwin.go b/proc/threads_darwin.go index e4470262..d12f3fd0 100644 --- a/proc/threads_darwin.go +++ b/proc/threads_darwin.go @@ -12,15 +12,7 @@ type OSSpecificDetails struct { registers C.x86_thread_state64_t } -func (t *Thread) Halt() (err error) { - defer func() { - if err == nil { - t.running = false - } - }() - if t.Stopped() { - return - } +func (t *Thread) halt() (err error) { kret := C.thread_suspend(t.os.thread_act) if kret != C.KERN_SUCCESS { errStr := C.GoString(C.mach_error_string(C.mach_error_t(kret))) diff --git a/proc/threads_linux.go b/proc/threads_linux.go index ecfa7a28..53cce505 100644 --- a/proc/threads_linux.go +++ b/proc/threads_linux.go @@ -12,15 +12,7 @@ type OSSpecificDetails struct { registers sys.PtraceRegs } -func (t *Thread) Halt() (err error) { - defer func() { - if err == nil { - t.running = false - } - }() - if t.Stopped() { - return - } +func (t *Thread) halt() (err error) { err = sys.Tgkill(t.dbp.Pid, t.Id, sys.SIGSTOP) if err != nil { err = fmt.Errorf("halt err %s on thread %d", err, t.Id)