| 1 |
// Copyright 2023 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 unix |
| 6 |
|
| 7 |
// The unix C definitions for trace.go. That file uses //export so |
| 8 |
// it can't put function definitions in the "C" import comment. |
| 9 |
|
| 10 |
#include <pthread.h> |
| 11 |
#include <assert.h> |
| 12 |
|
| 13 |
extern void goCalledFromC(void); |
| 14 |
extern void goCalledFromCThread(void); |
| 15 |
|
| 16 |
static void* cCalledFromCThread(void *p) { |
| 17 |
goCalledFromCThread(); |
| 18 |
return NULL; |
| 19 |
} |
| 20 |
|
| 21 |
void cCalledFromGo(void) { |
| 22 |
goCalledFromC(); |
| 23 |
|
| 24 |
pthread_t thread; |
| 25 |
assert(pthread_create(&thread, NULL, cCalledFromCThread, NULL) == 0); |
| 26 |
assert(pthread_join(thread, NULL) == 0); |
| 27 |
} |