Source file src/cmd/cgo/internal/test/issue6997_linux.go

     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  
     5  //go:build !android
     6  
     7  // Test that pthread_cancel works as expected
     8  // (NPTL uses SIGRTMIN to implement thread cancellation)
     9  // See https://golang.org/issue/6997
    10  package cgotest
    11  
    12  /*
    13  #cgo CFLAGS: -pthread
    14  #cgo LDFLAGS: -pthread
    15  extern int StartThread();
    16  extern int CancelThread();
    17  */
    18  import "C"
    19  
    20  import (
    21  	"testing"
    22  	"time"
    23  )
    24  
    25  func test6997(t *testing.T) {
    26  	r := C.StartThread()
    27  	if r != 0 {
    28  		t.Error("pthread_create failed")
    29  	}
    30  	c := make(chan C.int)
    31  	go func() {
    32  		time.Sleep(500 * time.Millisecond)
    33  		c <- C.CancelThread()
    34  	}()
    35  
    36  	select {
    37  	case r = <-c:
    38  		if r == 0 {
    39  			t.Error("pthread finished but wasn't canceled??")
    40  		}
    41  	case <-time.After(30 * time.Second):
    42  		t.Error("hung in pthread_cancel/pthread_join")
    43  	}
    44  }
    45  

View as plain text