• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//  (C) Copyright John Maddock 2001.
2//  Use, modification and distribution are subject to the
3//  Boost Software License, Version 1.0. (See accompanying file
4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6//  See http://www.boost.org/libs/config for most recent version.
7
8//  MACRO:         BOOST_HAS_PTHREADS
9//  TITLE:         POSIX Threads
10//  DESCRIPTION:   The platform supports POSIX style threads.
11
12#include <pthread.h>
13
14
15namespace boost_has_pthreads{
16
17extern "C" void* thread_proc(void* arg)
18{
19   return arg;
20}
21
22int test()
23{
24   pthread_mutex_t mut;
25   int result = pthread_mutex_init(&mut, 0);
26   if(0 == result)
27   {
28      //
29      // Failure to be able to create and use a mutex
30      // is always a failure, even if the pthread
31      // library is just a non-functioning stub.
32      //
33      result |= pthread_mutex_lock(&mut);
34      result |= pthread_mutex_unlock(&mut);
35      result |= pthread_mutex_trylock(&mut);
36      result |= pthread_mutex_unlock(&mut);
37      result |= pthread_mutex_destroy(&mut);
38      //
39      // Try and create a thread, this is allowed
40      // to fail, in case we are linking to a pthread
41      // "stub" library.
42      //
43      pthread_t t;
44      int r = pthread_create(&t, 0, &thread_proc, 0);
45      // result |= r;
46      if(r == 0)
47      {
48         //
49         // If we can create a thread, then we must be able to join to it:
50         //
51         void* arg;
52         r = pthread_join(t, &arg);
53         result |= r;
54      }
55   }
56   return result;
57}
58
59}
60
61
62
63
64
65