Source file misc/cgo/test/sigprocmask.go

     1  // Copyright 2015 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  // +build !windows
     6  
     7  package cgotest
     8  
     9  /*
    10  #cgo CFLAGS: -pthread
    11  #cgo LDFLAGS: -pthread
    12  extern int RunSigThread();
    13  extern int CheckBlocked();
    14  */
    15  import "C"
    16  import (
    17  	"os"
    18  	"os/signal"
    19  	"syscall"
    20  	"testing"
    21  )
    22  
    23  var blocked bool
    24  
    25  //export IntoGoAndBack
    26  func IntoGoAndBack() {
    27  	// Verify that SIGIO stays blocked on the C thread
    28  	// even when unblocked for signal.Notify().
    29  	signal.Notify(make(chan os.Signal), syscall.SIGIO)
    30  	blocked = C.CheckBlocked() != 0
    31  }
    32  
    33  func testSigprocmask(t *testing.T) {
    34  	if r := C.RunSigThread(); r != 0 {
    35  		t.Errorf("pthread_create/pthread_join failed: %d", r)
    36  	}
    37  	if !blocked {
    38  		t.Error("Go runtime unblocked SIGIO")
    39  	}
    40  }
    41  

View as plain text