Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
omp_get_max_threads crash in pthread body on OS X Snow Leopard using libgomp
$ gcc -Wall -g -lgomp nothread.c ; ./a.out ; echo $?
$ gcc -Wall -g -lgomp thread.c ; ./a.out ; echo $?
Segmentation fault
$ 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 ()
#include <omp.h>
int main(int argc, char **argv)
int retval = omp_get_max_threads();
return retval;
#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;

Context: I was trying to figure out why RMagick's Magick::Image.load was crashing when running in a Sinatra application run via rackup under rbx 2.0.0 and Ruby 1.9.2, but not

  1. in irb
  2. when running as a bare Sinatra app
  3. in rackup under Ruby 1.8.7

Turns out it has something to do with threads. get_omp_max_threads is 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 getting get_omp_max_threads to work in a threaded environment that I don't know about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.