cyphesis/tests/pthreadforce.cpp
Erik Ogenvik be18889fff Workaround for issue with pthread.
For some reason, when using the "gold" linker, pthread isn't dynamically
linked to as it should. The result is a segfault in std::locale at
startup.
By including an object which makes a side effect free call to a pthread
function we're making sure that pthread gets dynamically linked as it
should.
This might break on systems that aren't using pthreads, but I'm
currently just focusing on getting the tests not to segfault.
2014-09-30 23:36:10 +02:00

27 lines
1.1 KiB
C++

/*
Copyright (C) 2014 Erik Ogenvik
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
//For some reasons we're getting segfaults at startup in std::locale on some system. The "gold" linker seems to be the culprit.
//The cause appears to be that the pthreads library isn't recognized as needed. We therefore need to force its inclusion, which
//we'll do by calling the below function.
#include <pthread.h>
extern "C" {
pthread_t selfthread = pthread_self();
}