Created
August 2, 2011 17:30
-
-
Save hannahwhy/1120721 to your computer and use it in GitHub Desktop.
omp_get_max_threads crash in pthread body on OS X Snow Leopard using libgomp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ gcc -Wall -g -lgomp nothread.c ; ./a.out ; echo $? | |
| 2 | |
| $ gcc -Wall -g -lgomp thread.c ; ./a.out ; echo $? | |
| Segmentation fault | |
| 139 | |
| $ gdb ./a.out | |
| GNU gdb 6.3.50-20050815 (Apple version gdb-1518) (Sat Feb 12 02:52:12 UTC 2011) | |
| Copyright 2004 Free Software Foundation, Inc. | |
| GDB is free software, covered by the GNU General Public License, and you are | |
| welcome to change it and/or distribute copies of it under certain conditions. | |
| Type "show copying" to see the conditions. | |
| There is absolutely no warranty for GDB. Type "show warranty" for details. | |
| This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries .. done | |
| (gdb) r | |
| Starting program: ./a.out | |
| Reading symbols for shared libraries +. done | |
| Program received signal EXC_BAD_ACCESS, Could not access memory. | |
| Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000010 | |
| [Switching to process 99163 thread 0x417] | |
| 0x000000010000180c in gomp_resolve_num_threads () | |
| (gdb) bt | |
| #0 0x000000010000180c in gomp_resolve_num_threads () | |
| #1 0x0000000100002245 in thread_body (data=0x0) at thread.c:7 | |
| #2 0x00007fff8667c4f6 in _pthread_start () | |
| #3 0x00007fff8667c3a9 in thread_start () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <omp.h> | |
| int main(int argc, char **argv) | |
| { | |
| int retval = omp_get_max_threads(); | |
| return retval; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <pthread.h> | |
| #include <stdio.h> | |
| #include <omp.h> | |
| void *thread_body(void *data) | |
| { | |
| int foo = omp_get_max_threads(); | |
| /* suppress compiler warnings about unused variables */ | |
| printf("%d\n", foo); | |
| /* suppress compiler warnings about return values */ | |
| return NULL; | |
| } | |
| int main(int argc, char **argv) | |
| { | |
| int retval; | |
| pthread_t thread; | |
| retval = pthread_create(&thread, NULL, &thread_body, NULL); | |
| if (retval == 0) { | |
| pthread_join(thread, NULL); | |
| return 0; | |
| } else { | |
| return 254; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Context: I was trying to figure out why RMagick's
Magick::Image.loadwas crashing when running in a Sinatra application run via rackup under rbx 2.0.0 and Ruby 1.9.2, but notTurns out it has something to do with threads.
get_omp_max_threadsis sprinkled throughout Imagemagick's codebase, so I'm not quite sure how I'm going to fix this. (Disabling OpenMP is the quick fix, but that kind of sucks.) Maybe there's some way of gettingget_omp_max_threadsto work in a threaded environment that I don't know about.