E-MailRelay

gthread.cpp
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 Graeme Walker <graeme_walker@users.sourceforge.net>
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 of the License, or
7// (at your option) 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///
18/// \file gthread.cpp
19///
20
21#include "gdef.h"
22
23 namespace G
24{
25 namespace ThreadImp
26 {
27 void test_fn() {}
28 }
29}
30
31 bool G::threading::works()
32{
33 if( using_std_thread )
34 {
35 static bool first = true ;
36 static bool result = false ;
37 if( first )
38 {
39 first = false ;
40 try
41 {
42 threading::thread_type t( ThreadImp::test_fn ) ;
43 t.join() ;
44 threading::mutex_type mutex ;
45 threading::lock_type lock( mutex ) ;
46 result = true ;
47 }
48 catch(...)
49 {
50 // eg. gcc std::thread builds okay with -std=c++11 but throws
51 // at run-time if not also built with "-pthread" -- also, linking
52 // with -lGL suppresses linking with libpthread.so and breaks
53 // threading at run-time -- also, gcc 4.8 bugs
54 result = false ;
55 }
56 }
57 return result ;
58 }
59 else
60 {
61 return false ;
62 }
63}
64
G
Low-level classes.
Definition: galign.h:28