Code: Select all
try {
Image image( sFileName.c_str() );
image.type( GrayscaleType );
int imgWidth = image.columns();
int imgHeight = image.rows();
unsigned char *imageData = new unsigned char[imgWidth*imgHeight];
image.write(0,0, imgWidth, imgHeight, "I", MagickCore::CharPixel, imageData);
}
catch( Exception e ) { ...
The global structure of the program is as follows:
1. Load a reference image and store its pixels in a buffer.
2. Start multiple independent threads (through pthreads) that each do the following:
a. Load an image (using the above chunk of code) from a semaphore-protected queue.
b. Do some operations on the image image pixels and compare them with the reference buffer.
c. Report the comparison score in a semaphore-protected score array.
d. Back to a. or exit if the queue is empty.
This program has been running perfectly for years in both Linux and Mac OS X. It still runs perfectly in Linux, but since I moved from ImageMagick 6.4.1 to 6.5.8 in OS X (installed through Fink), it crashes with a bus error whenever I try to run the program with more than one thread. The crash occurs when the second thread tries to execute the Image() call in the chunk of code given above:
Code: Select all
(gdb) backtrace
#0 gomp_resolve_num_threads (specified=0) at /var/tmp/gcc/gcc-5646.1~2/src/libgomp/parallel.c:48
#1 0x00276c22 in omp_get_max_threads () at /var/tmp/gcc/gcc-5646.1~2/src/libgomp/parallel.c:96
#2 0x000f1c15 in AcquirePixelCache ()
#3 0x001aec2c in AcquireImage ()
#4 0x0005adc6 in Magick::ImageRef::ImageRef ()
#5 0x00056219 in Magick::Image::Image ()