issue6997_linux.c 535 B

12345678910111213141516171819202122232425262728
  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. // +build !android
  5. #include <pthread.h>
  6. #include <stdio.h>
  7. #include <unistd.h>
  8. static pthread_t thread;
  9. static void* threadfunc(void* dummy) {
  10. while(1) {
  11. sleep(1);
  12. }
  13. }
  14. int StartThread() {
  15. return pthread_create(&thread, NULL, &threadfunc, NULL);
  16. }
  17. int CancelThread() {
  18. void *r;
  19. pthread_cancel(thread);
  20. pthread_join(thread, &r);
  21. return (r == PTHREAD_CANCELED);
  22. }