| Summary: | PATCH: fix CMake tests for libpthread feature detection under Linux | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Scott Percival <code> |
| Component: | build | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | gabomdq, shirishag75 |
| Version: | HG 2.0 | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
| Attachments: |
Fix Linux pthread detection in CMake
Fix cmake test for PTHREADS_SEM |
||
|
Description
Scott Percival
2013-02-01 23:03:59 UTC
Created attachment 1032 [details]
Fix Linux pthread detection in CMake
Created attachment 1110 [details] Fix cmake test for PTHREADS_SEM Alternate patch. I ran into the same problem; system is (also) x86-64, Ubuntu 12.04.2, using cmake 2.8.7. Similar symptoms to Scott's, reached similar conclusions. Attached is the change I implemented to compile with cmake. Of particular note, LDFLAGS went under CMAKE_REQUIRED_LIBRARIES, so that the "-lpthread" switch shows up towards the end of the command line, where it's available for resolving(?) pthread symbols. In any case, putting "-lpthread" at the end made compiles work better. Documentation for cmake 2.8.7 indicates CHECK_C_SOURCE_COMPILES requires main() to be in there: > <code> - source code to try to compile, must define 'main' As an aside, docs for gcc-4.6 lists "-pthread" for only RS/6000, PowerPC, and Solaris 2. Docs imply the switch is semi-magical to get pthreads to work on those platforms. I think the switch is unnecessary/excessive under "LINUX". Fixed in http://hg.libsdl.org/SDL/rev/a2bddc1fb02f. For reference, some of the stuff I found out while researching the issue... Solving the deadlocks was achieved by adding -pthread in the LDFLAGS. That alone seemed to be enough to get "torturethread" working. Why? When HAVE_PTHREAD_SEM is not defined (in this case because the test was faulty *and* we were missing the -pthread flag), the script includes generic/SDL_syssem.c, which in turn uses SDL_LockMutex which uses pthreads. Something (AFAICT it's an issue with reentrant threads, but I'm not 100% certain) makes pthread_mutex_lock fail if -pthread was not provided when compiling, but I'm fairly certain it's not our responsibility. I did go further down the rabbit hole, and configured with --disable-pthreads. On Linux, this has the effect of defining SDL_THREADS_DISABLED so you get no thread support (generic doesn't kick in). I tried to hack around this (undefining SDL_THREADS_DISABLED), to discover a recursion issue on the generic code (which I don't know if it's intended or not)...the generic version of SDL_CreateSemaphore calls the generic version of SDL_CreateMutex and then the generic version of SDL_CreateMutex calls SDL_CreateSemaphore, etc...infinite recursion (which doesn't happen if you use only one of those functions, as is the case when HAVE_PTHREAD_SEM is not defined). In the end Sam told me that by design the platform has to provide either semaphores or mutexes, which makes sense (if you have neither, threading will be disabled). |