issue6997_linux.go 898 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //go:build !android
  5. // +build !android
  6. // Test that pthread_cancel works as expected
  7. // (NPTL uses SIGRTMIN to implement thread cancellation)
  8. // See https://golang.org/issue/6997
  9. package cgotest
  10. /*
  11. #cgo CFLAGS: -pthread
  12. #cgo LDFLAGS: -pthread
  13. extern int StartThread();
  14. extern int CancelThread();
  15. */
  16. import "C"
  17. import (
  18. "testing"
  19. "time"
  20. )
  21. func test6997(t *testing.T) {
  22. r := C.StartThread()
  23. if r != 0 {
  24. t.Error("pthread_create failed")
  25. }
  26. c := make(chan C.int)
  27. go func() {
  28. time.Sleep(500 * time.Millisecond)
  29. c <- C.CancelThread()
  30. }()
  31. select {
  32. case r = <-c:
  33. if r == 0 {
  34. t.Error("pthread finished but wasn't canceled??")
  35. }
  36. case <-time.After(30 * time.Second):
  37. t.Error("hung in pthread_cancel/pthread_join")
  38. }
  39. }