I have a utility which processes a sequence of images. When multiple threads are enabled I get a very repeatable deadlock inside Image::border(). I added some debugging statements and the call to BorderImage() does not return. If there is only one thread this problem does not occur.
I just upgraded to version 6.5.7.2. With the prior version I was using (6.5.3.10 I believe), I would get a segmentation fault under the same multi-threaded scenario in the call to border.
I am building with threads enabled. This is on Ubuntu 9.04 with:
gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu4)
Any ideas would be appreciated.
deadlock inside Image::border()
Re: deadlock inside Image::border()
Can you post a small program that illustrates the problem? We created 25 threads with 5 iterations with a random border and it ran without complaint (no deadlocks) We're using ImageMagick 6.5.7-2 and gcc 4.4.1.
Re: deadlock inside Image::border()
Here is a short program with which I see a problem. So far, it hasn't gone passed 6 loops. My input image is 1920x1080 TGA, but I do not thing it is image dependent. Thank you for your help.
Code: Select all
//
// g++ -o deadlock -D_REENTRANT -I/usr/local/include/ImageMagick deadlock.cpp -lpthread -lMagick++
//
#include <iostream>
#include <pthread.h>
#include <Magick++.h>
struct stuff
{
const char *name;
const char *sgeometry;
const char *scolor;
};
void * process( void *v )
{
struct stuff *params = (struct stuff *)v;
Magick::Image image;
image.read(params->name);
image.modifyImage();
// Magick::Color c(params->scolor);
// image.borderColor(c);
Magick::Geometry g(params->sgeometry);
image.border(g);
return NULL;
}
int main(int argc, char *argv[])
{
pthread_t threads[4];
struct stuff params;
params.name = argv[1];
params.sgeometry = "64x0";
params.scolor = "LimeGreen";
Magick::InitializeMagick( "" );
for (int j = 0 ; j < 20 ; j++ )
{
std::cout << "pass " << j << std::endl;
for (int i = 0 ; i < 4 ; i++)
{
std::cout << " thread " << i << " created" << std::endl;
pthread_create(&threads[i], NULL, process, (void *)¶ms);
}
for (int i = 0 ; i < 4 ; i++)
{
pthread_join(threads[i], NULL);
std::cout << " thread " << i << " joined" << std::endl;
}
}
}
Re: deadlock inside Image::border()
Your program worked without complaint for us. We're using ImageMagick 6.5.7-3 and gcc 4.4.2:
Code: Select all
-> magick++ magick++.png
pass 0
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 1
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 2
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 3
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 4
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 5
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 6
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 7
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 8
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 9
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 10
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 11
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 12
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 13
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 14
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 15
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 16
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 17
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 18
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
pass 19
thread 0 created
thread 1 created
thread 2 created
thread 3 created
thread 0 joined
thread 1 joined
thread 2 joined
thread 3 joined
Re: deadlock inside Image::border()
Where can I find 6.5.7-3?magick wrote:Your program worked without complaint for us. We're using ImageMagick 6.5.7-3 and gcc 4.4.2:
Re: deadlock inside Image::border()
ImageMagick-6.5-7-3 will be available within an hour or so on ftp://ftp.imagemagick.org/pub/ImageMagick. If it still hangs, try adding -disable-openmp on your configure command line. We have seen some buggy releases of libgomp.
Re: deadlock inside Image::border()
At least with 6.5.7-2, --disable-openmp fails to link with a number of undefined references to GOMP symbols. I will try 6.5.7-3. I'm not sure what to try beyond this.magick wrote:We have seen some buggy releases of libgomp.
Re: deadlock inside Image::border()
I think your suspicions about libgomp are right. If I reduce the number of threads my test ran through fine 5 times in a row:magick wrote:If it still hangs, try adding -disable-openmp on your configure command line. We have seen some buggy releases of libgomp.
$ export OMP_NUM_THREADS=1
$ ./deadlock deadlock.png