1/* Multithreading primitives. 2 Copyright (C) 2005-2010 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 Lesser General Public License as published by 6 the Free Software Foundation; either version 2, 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 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public License 15 along with this program; if not, write to the Free Software Foundation, 16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 17 18/* Written by Bruno Haible <bruno@clisp.org>, 2005. */ 19 20#include <config.h> 21 22/* ========================================================================= */ 23 24#if USE_POSIX_THREADS 25 26/* Use the POSIX threads library. */ 27 28# include <pthread.h> 29# include <stdlib.h> 30 31# if PTHREAD_IN_USE_DETECTION_HARD 32 33/* The function to be executed by a dummy thread. */ 34static void * 35dummy_thread_func (void *arg) 36{ 37 return arg; 38} 39 40int 41glthread_in_use (void) 42{ 43 static int tested; 44 static int result; /* 1: linked with -lpthread, 0: only with libc */ 45 46 if (!tested) 47 { 48 pthread_t thread; 49 50 if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0) 51 /* Thread creation failed. */ 52 result = 0; 53 else 54 { 55 /* Thread creation works. */ 56 void *retval; 57 if (pthread_join (thread, &retval) != 0) 58 abort (); 59 result = 1; 60 } 61 tested = 1; 62 } 63 return result; 64} 65 66# endif 67 68#endif 69 70/* ========================================================================= */ 71 72/* This declaration is solely to ensure that after preprocessing 73 this file is never empty. */ 74typedef int dummy; 75