当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.Gettid函数代码示例

本文整理汇总了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
}
开发者ID:wcwxyz,项目名称:libnetwork,代码行数:8,代码来源:namespace_linux.go

示例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()
}
开发者ID:danny8002,项目名称:go,代码行数:9,代码来源:runtime_linux_test.go

示例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
}
开发者ID:JonnieCache,项目名称:rigwars,代码行数:16,代码来源:system_test.go

示例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()
}
开发者ID:magenbluten,项目名称:godit,代码行数:20,代码来源:suspend_linux.go

示例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)
}
开发者ID:aimeiyan,项目名称:gocode,代码行数:20,代码来源:pid.go

示例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")
		}
	}
}
开发者ID:achanda,项目名称:go,代码行数:21,代码来源:cgo_thread_lock.go

示例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()
}
开发者ID:rdarder,项目名称:goworkers,代码行数:23,代码来源:workers.go

示例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
}
开发者ID:justone,项目名称:docker,代码行数:37,代码来源:namespace_linux.go

示例9: Setfscreatecon

func Setfscreatecon(scon string) error {
	return writeCon(fmt.Sprintf("/proc/self/task/%d/attr/fscreate", syscall.Gettid()), scon)
}
开发者ID:Altiscale,项目名称:runc,代码行数:3,代码来源:selinux.go

示例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"))
			})
		})
	})
开发者ID:cloudfoundry-incubator,项目名称:ducati-daemon,代码行数:31,代码来源:namespace_test.go

示例11: getLink

func getLink() (string, error) {
	return os.Readlink(fmt.Sprintf("/proc/%d/task/%d/ns/net", os.Getpid(), syscall.Gettid()))
}
开发者ID:CadeLaRen,项目名称:docker-3,代码行数:3,代码来源:init_linux.go

示例12: Exit

func (f *FakeSystem) Exit() {
	f.exitTids = AppendTid(f.exitTids, syscall.Gettid())

	f.exitCount++
}
开发者ID:JonnieCache,项目名称:rigwars,代码行数:5,代码来源:system_test.go

示例13: getThreadID

// getThreadID returns an opaque value that is unique per OS thread
func getThreadID() uintptr {
	return uintptr(syscall.Gettid())
}
开发者ID:crewjam,项目名称:go-xmlsec,代码行数:4,代码来源:thread_linux.go

示例14: Setexeccon

func Setexeccon(scon string) error {
	return writeCon(fmt.Sprintf("/proc/self/task/%d/attr/exec", syscall.Gettid()), scon)
}
开发者ID:Altiscale,项目名称:runc,代码行数:3,代码来源:selinux.go

示例15: Getfscreatecon

func Getfscreatecon() (string, error) {
	return readCon(fmt.Sprintf("/proc/self/task/%d/attr/fscreate", syscall.Gettid()))
}
开发者ID:Altiscale,项目名称:runc,代码行数:3,代码来源:selinux.go


注:本文中的syscall.Gettid函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。