1 /* Multithreading primitives. 2 Copyright (C) 2005-2012 Free Software Foundation, Inc. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 3, or (at your option) 7 any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 16 17 /* Written by Bruno Haible <bruno (at) clisp.org>, 2005. */ 18 19 #include <config.h> 20 21 /* ========================================================================= */ 22 23 #if USE_POSIX_THREADS 24 25 /* Use the POSIX threads library. */ 26 27 # include <pthread.h> 28 # include <stdlib.h> 29 30 # if PTHREAD_IN_USE_DETECTION_HARD 31 32 /* The function to be executed by a dummy thread. */ 33 static void * 34 dummy_thread_func (void *arg) 35 { 36 return arg; 37 } 38 39 int 40 glthread_in_use (void) 41 { 42 static int tested; 43 static int result; /* 1: linked with -lpthread, 0: only with libc */ 44 45 if (!tested) 46 { 47 pthread_t thread; 48 49 if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0) 50 /* Thread creation failed. */ 51 result = 0; 52 else 53 { 54 /* Thread creation works. */ 55 void *retval; 56 if (pthread_join (thread, &retval) != 0) 57 abort (); 58 result = 1; 59 } 60 tested = 1; 61 } 62 return result; 63 } 64 65 # endif 66 67 #endif 68 69 /* ========================================================================= */ 70 71 /* This declaration is solely to ensure that after preprocessing 72 this file is never empty. */ 73 typedef int dummy; 74