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


Golang runtime.LockOSThread函数代码示例

本文整理汇总了Golang中runtime.LockOSThread函数的典型用法代码示例。如果您正苦于以下问题:Golang LockOSThread函数的具体用法?Golang LockOSThread怎么用?Golang LockOSThread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了LockOSThread函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestSandboxCreateTwice

func TestSandboxCreateTwice(t *testing.T) {
	defer SetupTestOSContext(t)()

	key, err := newKey(t)
	if err != nil {
		t.Fatalf("Failed to obtain a key: %v", err)
	}

	_, err = NewSandbox(key, true)
	if err != nil {
		t.Fatalf("Failed to create a new sandbox: %v", err)
	}
	runtime.LockOSThread()

	// Create another sandbox with the same key to see if we handle it
	// gracefully.
	s, err := NewSandbox(key, true)
	if err != nil {
		t.Fatalf("Failed to create a new sandbox: %v", err)
	}
	runtime.LockOSThread()

	err = s.Destroy()
	if err != nil {
		t.Fatal(err)
	}
	GC()
	verifyCleanup(t, s, false)
}
开发者ID:rajatchopra,项目名称:libnetwork,代码行数:29,代码来源:sandbox_test.go

示例2: TestRef

func TestRef(t *testing.T) {
	const N = 10
	runtime.LockOSThread()
	wg := sync.WaitGroup{}
	wg.Add(N)
	ch := make(chan uintptr)
	for i := 0; i < N; i++ {
		go func() {
			runtime.LockOSThread()
			wg.Done()
			ch <- Ref()
			wg.Wait()
		}()
	}
	wg.Wait()
	refs := []uintptr{Ref()}
	for i := 0; i < N; i++ {
		chref := <-ch
		for _, ref := range refs {
			if chref == ref {
				t.Fatalf("found duplicated ref: %d == %d", chref, ref)
			}
		}
		refs = append(refs, chref)
	}
}
开发者ID:happyluo,项目名称:qml,代码行数:26,代码来源:tref_test.go

示例3: Init

func Init() {
	runtime.LockOSThread()

	err := glfw.Init()
	if err != nil {
		panic(fmt.Sprintf("glfw.Init() fails: %v", err))
	}
	glfw.WindowHint(glfw.Visible, glfw.False)
	glfw.WindowHint(glfw.Resizable, glfw.False)

	// As start, create an window with temporary size to create OpenGL context thread.
	window, err := glfw.CreateWindow(16, 16, "", nil, nil)
	if err != nil {
		panic(err)
	}

	u := &userInterface{
		window: window,
		funcs:  make(chan func()),
	}
	go func() {
		runtime.LockOSThread()
		u.window.MakeContextCurrent()
		glfw.SwapInterval(1)
		for f := range u.funcs {
			f()
		}
	}()

	currentUI = u
}
开发者ID:DrJosh9000,项目名称:ebiten,代码行数:31,代码来源:ui_glfw.go

示例4: TestRef

func TestRef(t *testing.T) {
	const N = 10
	runtime.LockOSThread()
	exit := sync.WaitGroup{}
	exit.Add(1)
	defer exit.Done()
	wg := sync.WaitGroup{}
	wg.Add(N)
	ch := make(chan refPair)
	for i := 0; i < N; i++ {
		go func() {
			runtime.LockOSThread()
			wg.Done()
			ch <- refPair{Ref(), Ref()}
			exit.Wait()
		}()
	}
	wg.Wait()
	refs := make(map[uintptr]bool)
	for i := 0; i < N; i++ {
		pair := <-ch
		if pair.ref1 != pair.ref2 {
			t.Fatalf("found inconsistent ref: %d != %d", pair.ref1, pair.ref2)
		}
		if refs[pair.ref1] {
			t.Fatalf("found duplicated ref: %d", pair.ref1)
		}
		refs[pair.ref1] = true
	}
}
开发者ID:CedarLogic,项目名称:go-ethereum,代码行数:30,代码来源:cdata_test.go

示例5: TestEndpointDeleteWithActiveContainer

func TestEndpointDeleteWithActiveContainer(t *testing.T) {
	if !netutils.IsRunningInContainer() {
		defer netutils.SetupTestNetNS(t)()
	}

	n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
		netlabel.GenericData: options.Generic{
			"BridgeName":            "testnetwork",
			"AllowNonDefaultBridge": true,
		},
	})
	if err != nil {
		t.Fatal(err)
	}
	defer func() {
		if err := n.Delete(); err != nil {
			t.Fatal(err)
		}
	}()

	ep, err := n.CreateEndpoint("ep1")
	if err != nil {
		t.Fatal(err)
	}
	defer func() {
		err = ep.Delete()
		if err != nil {
			t.Fatal(err)
		}
	}()

	defer controller.LeaveAll(containerID)

	err = ep.Join(containerID,
		libnetwork.JoinOptionHostname("test"),
		libnetwork.JoinOptionDomainname("docker.io"),
		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
	runtime.LockOSThread()
	if err != nil {
		t.Fatal(err)
	}
	defer func() {
		err = ep.Leave(containerID)
		runtime.LockOSThread()
		if err != nil {
			t.Fatal(err)
		}
	}()

	err = ep.Delete()
	if err == nil {
		t.Fatal("Expected to fail. But instead succeeded")
	}

	if _, ok := err.(*libnetwork.ActiveContainerError); !ok {
		t.Fatalf("Did not fail with expected error. Actual error: %v", err)
	}
}
开发者ID:aduermael,项目名称:libnetwork,代码行数:58,代码来源:libnetwork_test.go

示例6: TestEndpointMultipleJoins

func TestEndpointMultipleJoins(t *testing.T) {
	if !netutils.IsRunningInContainer() {
		defer netutils.SetupTestNetNS(t)()
	}

	n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
		netlabel.GenericData: options.Generic{
			"BridgeName":            "testnetwork",
			"AllowNonDefaultBridge": true,
		},
	})
	if err != nil {
		t.Fatal(err)
	}
	defer func() {
		if err := n.Delete(); err != nil {
			t.Fatal(err)
		}
	}()

	ep, err := n.CreateEndpoint("ep1")
	if err != nil {
		t.Fatal(err)
	}
	defer func() {
		if err := ep.Delete(); err != nil {
			t.Fatal(err)
		}
	}()

	defer controller.LeaveAll(containerID)

	err = ep.Join(containerID,
		libnetwork.JoinOptionHostname("test"),
		libnetwork.JoinOptionDomainname("docker.io"),
		libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
	runtime.LockOSThread()
	if err != nil {
		t.Fatal(err)
	}
	defer func() {
		err = ep.Leave(containerID)
		runtime.LockOSThread()
		if err != nil {
			t.Fatal(err)
		}
	}()

	err = ep.Join("container2")
	if err == nil {
		t.Fatal("Expected to fail multiple joins for the same endpoint")
	}

	if _, ok := err.(libnetwork.ErrInvalidJoin); !ok {
		t.Fatalf("Failed for unexpected reason: %v", err)
	}
}
开发者ID:aduermael,项目名称:libnetwork,代码行数:57,代码来源:libnetwork_test.go

示例7: GoRun

//export GoRun
func GoRun() {
	runtime.LockOSThread()
	c := make(chan bool)
	go func() {
		runtime.LockOSThread()
		C.setVal(2)
		c <- true
	}()
	<-c
}
开发者ID:Greentor,项目名称:go,代码行数:11,代码来源:tsan2.go

示例8: TestSandboxCreate

func TestSandboxCreate(t *testing.T) {
	defer SetupTestOSContext(t)()

	key, err := newKey(t)
	if err != nil {
		t.Fatalf("Failed to obtain a key: %v", err)
	}

	s, err := NewSandbox(key, true)
	if err != nil {
		t.Fatalf("Failed to create a new sandbox: %v", err)
	}
	runtime.LockOSThread()

	if s.Key() != key {
		t.Fatalf("s.Key() returned %s. Expected %s", s.Key(), key)
	}

	tbox, err := newInfo(t)
	if err != nil {
		t.Fatalf("Failed to generate new sandbox info: %v", err)
	}

	for _, i := range tbox.Info().Interfaces() {
		err = s.AddInterface(i.SrcName(), i.DstName(),
			tbox.InterfaceOptions().Bridge(i.Bridge()),
			tbox.InterfaceOptions().Address(i.Address()),
			tbox.InterfaceOptions().AddressIPv6(i.AddressIPv6()))
		if err != nil {
			t.Fatalf("Failed to add interfaces to sandbox: %v", err)
		}
		runtime.LockOSThread()
	}

	err = s.SetGateway(tbox.Info().Gateway())
	if err != nil {
		t.Fatalf("Failed to set gateway to sandbox: %v", err)
	}
	runtime.LockOSThread()

	err = s.SetGatewayIPv6(tbox.Info().GatewayIPv6())
	if err != nil {
		t.Fatalf("Failed to set ipv6 gateway to sandbox: %v", err)
	}
	runtime.LockOSThread()

	verifySandbox(t, s, []string{"0", "1", "2"})
	runtime.LockOSThread()

	err = s.Destroy()
	if err != nil {
		t.Fatal(err)
	}
	verifyCleanup(t, s, true)
}
开发者ID:rajatchopra,项目名称:libnetwork,代码行数:55,代码来源:sandbox_test.go

示例9: TestLeaveAll

func TestLeaveAll(t *testing.T) {
	if !testutils.IsRunningInContainer() {
		defer testutils.SetupTestOSContext(t)()
	}

	n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
		netlabel.GenericData: options.Generic{
			"BridgeName": "testnetwork",
		},
	}, nil, nil)
	if err != nil {
		t.Fatal(err)
	}
	defer func() {
		// If this goes through, it means cnt.Delete() effectively detached from all the endpoints
		if err := n.Delete(); err != nil {
			t.Fatal(err)
		}
	}()

	ep1, err := n.CreateEndpoint("ep1")
	if err != nil {
		t.Fatal(err)
	}

	ep2, err := n.CreateEndpoint("ep2")
	if err != nil {
		t.Fatal(err)
	}

	cnt, err := controller.NewSandbox("leaveall")
	if err != nil {
		t.Fatal(err)
	}

	err = ep1.Join(cnt)
	if err != nil {
		t.Fatalf("Failed to join ep1: %v", err)
	}
	runtime.LockOSThread()

	err = ep2.Join(cnt)
	if err != nil {
		t.Fatalf("Failed to join ep2: %v", err)
	}
	runtime.LockOSThread()

	err = cnt.Delete()
	if err != nil {
		t.Fatal(err)
	}
}
开发者ID:pirater,项目名称:os,代码行数:52,代码来源:libnetwork_test.go

示例10: CgoSignalDeadlock

func CgoSignalDeadlock() {
	runtime.GOMAXPROCS(100)
	ping := make(chan bool)
	go func() {
		for i := 0; ; i++ {
			runtime.Gosched()
			select {
			case done := <-ping:
				if done {
					ping <- true
					return
				}
				ping <- true
			default:
			}
			func() {
				defer func() {
					recover()
				}()
				var s *string
				*s = ""
			}()
		}
	}()
	time.Sleep(time.Millisecond)
	for i := 0; i < 64; i++ {
		go func() {
			runtime.LockOSThread()
			select {}
		}()
		go func() {
			runtime.LockOSThread()
			select {}
		}()
		time.Sleep(time.Millisecond)
		ping <- false
		select {
		case <-ping:
		case <-time.After(time.Second):
			fmt.Printf("HANG\n")
			return
		}
	}
	ping <- true
	select {
	case <-ping:
	case <-time.After(time.Second):
		fmt.Printf("HANG\n")
		return
	}
	fmt.Printf("OK\n")
}
开发者ID:RajibTheKing,项目名称:gcc,代码行数:52,代码来源:cgo.go

示例11: main

func main() {
	runtime.LockOSThread()

	// initialize glfw
	if err := glfw.Init(); err != nil {
		log.Fatalln("Failed to initialize GLFW: ", err)
	}
	defer glfw.Terminate()

	// create window
	window, err := glfw.CreateWindow(1280, 720, os.Args[0], nil, nil)
	if err != nil {
		log.Fatal(err)
	}
	window.SetFramebufferSizeCallback(onResize)
	window.MakeContextCurrent()

	if err := gl.Init(); err != nil {
		log.Fatal(err)
	}

	// set up opengl context
	onResize(window, 600, 600)
	// player = createPlayer()
	// addBall()
	// set up physics

	game = engine.NewGame()

	game.Init()
	game.ReadLevelFromFile("level.json")

	//Init Controlls I think
	// glfw.KeyCallback(window)
	window.SetKeyCallback(keyCallback)

	runtime.LockOSThread()
	glfw.SwapInterval(1)

	ticker := time.NewTicker(time.Second / 60)
	for !window.ShouldClose() {

		game.Update(1.0 / 60.0)

		draw()
		window.SwapBuffers()
		glfw.PollEvents()

		<-ticker.C // wait up to 1/60th of a second
	}
}
开发者ID:jhautefeuille,项目名称:hellochipmunk,代码行数:51,代码来源:main.go

示例12: init

func init() {
	if DoItTheRightWay {
		runtime.LockOSThread()
	}
	C.initMacDraw()
	if !DoItTheRightWay {
		go func() {
			runtime.LockOSThread()
			<-appChanStart
			C.NSAppRun()
			appChanFinish <- true
		}()
	}
}
开发者ID:waxcorp,项目名称:gmd,代码行数:14,代码来源:gmdgo.go

示例13: main

func main() {
	runtime.LockOSThread()
	C.setVal(1)
	c := make(chan bool)
	go func() {
		runtime.LockOSThread()
		C.setVal(2)
		c <- true
	}()
	<-c
	if v := C.getVal(); v != 2 {
		panic(v)
	}
}
开发者ID:sreis,项目名称:go,代码行数:14,代码来源:tsan.go

示例14: Clone

func Clone(url string, path string, options *CloneOptions) (*Repository, error) {
	repo := new(Repository)

	curl := C.CString(url)
	defer C.free(unsafe.Pointer(curl))

	cpath := C.CString(path)
	defer C.free(unsafe.Pointer(cpath))

	var copts C.git_clone_options
	populateCloneOptions(&copts, options)
	defer freeCheckoutOpts(&copts.checkout_opts)

	if len(options.CheckoutBranch) != 0 {
		copts.checkout_branch = C.CString(options.CheckoutBranch)
		defer C.free(unsafe.Pointer(copts.checkout_branch))
	}

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()
	ret := C.git_clone(&repo.ptr, curl, cpath, &copts)
	if ret < 0 {
		return nil, MakeGitError(ret)
	}

	runtime.SetFinalizer(repo, (*Repository).Free)
	return repo, nil
}
开发者ID:jezell,项目名称:git2go,代码行数:28,代码来源:clone.go

示例15: SetSymbolicTarget

func (v *Reference) SetSymbolicTarget(target string, sig *Signature, msg string) (*Reference, error) {
	var ptr *C.git_reference

	ctarget := C.CString(target)
	defer C.free(unsafe.Pointer(ctarget))

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	csig := sig.toC()
	defer C.free(unsafe.Pointer(csig))

	var cmsg *C.char
	if msg == "" {
		cmsg = nil
	} else {
		cmsg = C.CString(msg)
		defer C.free(unsafe.Pointer(cmsg))
	}

	ret := C.git_reference_symbolic_set_target(&ptr, v.ptr, ctarget, csig, cmsg)
	if ret < 0 {
		return nil, MakeGitError(ret)
	}

	return newReferenceFromC(ptr), nil
}
开发者ID:jingweno,项目名称:git2go,代码行数:27,代码来源:reference.go


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