summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/futex_test.go
blob: f4054b7e78075fa7790661348cc9ac0a99f48d43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2013 The Go Authors.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Futex is only available on Dragonfly, FreeBSD and Linux.
// The race detector emits calls to split stack functions so it breaks the test.
// +build dragonfly freebsd linux
// +build !race

package runtime_test

import (
	. "runtime"
	"testing"
	"time"
)

func TestFutexsleep(t *testing.T) {
	ch := make(chan bool, 1)
	var dummy uint32
	start := time.Now()
	go func() {
		Entersyscall()
		Futexsleep(&dummy, 0, (1<<31+100)*1e9)
		Exitsyscall()
		ch <- true
	}()
	select {
	case <-ch:
		t.Errorf("futexsleep finished early after %s!", time.Since(start))
	case <-time.After(time.Second):
		Futexwakeup(&dummy, 1)
	}
}