本文整理汇总了Golang中syscall.Gettid函数的典型用法代码示例。如果您正苦于以下问题:Golang Gettid函数的具体用法?Golang Gettid怎么用?Golang Gettid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Gettid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getLink
func getLink() string {
l, err := os.Readlink(fmt.Sprintf("/proc/%d/task/%d/ns/net", os.Getpid(), syscall.Gettid()))
if err != nil {
return fmt.Sprintf("(nil: %v)", err)
}
return l
}
示例2: init
func init() {
// Record pid and tid of init thread for use during test.
// The call to LockOSThread is just to exercise it;
// we can't test that it does anything.
// Instead we're testing that the conditions are good
// for how it is used in init (must be on main thread).
pid, tid = syscall.Getpid(), syscall.Gettid()
LockOSThread()
}
示例3: Update
func (f *FakeSystem) Update(timestep time.Duration) (stop bool, err error) {
f.updateTids = AppendTid(f.updateTids, syscall.Gettid())
f.updateCount++
if f.updateCount >= f.maxUpdates {
stop = true
}
f.totalTimeMs += float64(timestep.Nanoseconds()) / 1000000
runtime.Gosched()
stop = stop || f.updateReturnStop
err = f.updateReturnErr
return
}
示例4: suspend
func suspend(g *godit) {
// finalize termbox
termbox.Close()
// suspend the process
pid := syscall.Getpid()
tid := syscall.Gettid()
err := syscall.Tgkill(pid, tid, syscall.SIGSTOP)
if err != nil {
panic(err)
}
// reset the state so we can get back to work again
err = termbox.Init()
if err != nil {
panic(err)
}
termbox.SetInputMode(termbox.InputAlt)
g.resize()
}
示例5: main
func main() {
fmt.Println("--------", runtime.GOMAXPROCS(runtime.NumCPU()), runtime.NumCPU())
for i := 0; i < 10; i++ {
go func(id int) {
ch := time.Tick(time.Second * 4)
for now := range ch {
// bounce bettween many threads => a goroutine can be run by any real thread
fmt.Printf("%v pid: %d:%d\n", now, syscall.Gettid(), id)
}
// for j := 0; j < 10; j++ {
// fmt.Println("pid is:", )
// time.Sleep(time.Second * 3)
// }
}(i)
}
time.Sleep(time.Second * 300)
}
示例6: testThreadLock
func testThreadLock(t *testing.T) {
stop := make(chan int)
go func() {
// We need the G continue running,
// so the M has a chance to run this G.
for {
select {
case <-stop:
return
case <-time.After(time.Millisecond * 100):
}
}
}()
defer close(stop)
for i := 0; i < 1000; i++ {
if C.int(syscall.Gettid()) != C.Ctid() {
t.Fatalf("cgo has not locked OS thread")
}
}
}
示例7: find_unused_thread
func find_unused_thread(tries int, wg *sync.WaitGroup, reg *pidRegistry, worker func()) {
for i := 0; i <= tries; i++ {
reg.lock.Lock()
runtime.LockOSThread()
pid := syscall.Gettid()
if _, taken := reg.pids[pid]; !taken {
reg.pids[pid] = true
reg.lock.Unlock()
runtime.Gosched() //block to aid context switching
worker()
reg.lock.Lock()
delete(reg.pids, pid)
reg.lock.Unlock()
wg.Done()
return
} else {
reg.lock.Unlock()
runtime.UnlockOSThread()
}
}
log.Println("goroutine given up finding a new thread")
wg.Done()
}
示例8: createNetworkNamespace
func createNetworkNamespace(path string, osCreate bool) (*Info, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
origns, err := netns.Get()
if err != nil {
return nil, err
}
defer origns.Close()
if err := createNamespaceFile(path); err != nil {
return nil, err
}
if osCreate {
defer netns.Set(origns)
newns, err := netns.New()
if err != nil {
return nil, err
}
defer newns.Close()
if err := loopbackUp(); err != nil {
return nil, err
}
}
procNet := fmt.Sprintf("/proc/%d/task/%d/ns/net", os.Getpid(), syscall.Gettid())
if err := syscall.Mount(procNet, path, "bind", syscall.MS_BIND, ""); err != nil {
return nil, err
}
interfaces := []*Interface{}
info := &Info{Interfaces: interfaces}
return info, nil
}
示例9: Setfscreatecon
func Setfscreatecon(scon string) error {
return writeCon(fmt.Sprintf("/proc/self/task/%d/attr/fscreate", syscall.Gettid()), scon)
}
示例10:
It("locks and unlocks the os thread", func() {
err := ns.Execute(func(*os.File) error {
defer GinkgoRecover()
Expect(threadLocker.LockOSThreadCallCount()).To(Equal(1))
Expect(threadLocker.UnlockOSThreadCallCount()).To(Equal(0))
return nil
})
Expect(err).NotTo(HaveOccurred())
Expect(threadLocker.LockOSThreadCallCount()).To(Equal(1))
Expect(threadLocker.UnlockOSThreadCallCount()).To(Equal(1))
})
It("runs the callback on a separate os task", func() {
var ttid int
err := ns.Execute(func(*os.File) error {
ttid = syscall.Gettid()
return nil
})
Expect(err).NotTo(HaveOccurred())
Expect(syscall.Gettid()).NotTo(Equal(ttid))
})
Context("when the callback fails", func() {
It("logs the error", func() {
ns.Execute(func(*os.File) error { return errors.New("potato") })
Expect(logger).To(gbytes.Say("execute.callback-failed.*potato"))
})
})
})
示例11: getLink
func getLink() (string, error) {
return os.Readlink(fmt.Sprintf("/proc/%d/task/%d/ns/net", os.Getpid(), syscall.Gettid()))
}
示例12: Exit
func (f *FakeSystem) Exit() {
f.exitTids = AppendTid(f.exitTids, syscall.Gettid())
f.exitCount++
}
示例13: getThreadID
// getThreadID returns an opaque value that is unique per OS thread
func getThreadID() uintptr {
return uintptr(syscall.Gettid())
}
示例14: Setexeccon
func Setexeccon(scon string) error {
return writeCon(fmt.Sprintf("/proc/self/task/%d/attr/exec", syscall.Gettid()), scon)
}
示例15: Getfscreatecon
func Getfscreatecon() (string, error) {
return readCon(fmt.Sprintf("/proc/self/task/%d/attr/fscreate", syscall.Gettid()))
}