graphicsmagick bugs in multi threads programs
"王利超" <[email protected]> Wed, 8 May 2013 18:52:58 +0800
| Newsgroups | gmane.comp.video.graphicsmagick.bugs |
|---|---|
| Message-ID | <[email protected]> |
hi,all:
I find GraphicsMagick doesn't work well if the program self is multi thread。The CPU is only 200% (my computer is 16 core).
The C++ API of GraphicsMagick is not working when users program is multi thread,openMP in GraphicsMagick is not like paralle process.
My test GraphicsMagick versions are :1.3.18 ,1.3.17 ,1.3.16
single threads test case is like:
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <magick/api.h>
#include <boost/thread/thread.hpp>
using namespace std;
void exec(const char *pic) {
char outfile[MaxTextExtent];
(void) strncpy( outfile, "resize.jpg", MaxTextExtent-1 );
ExceptionInfo exception;
Image *image,
*resize_image;
ImageInfo *image_info;
GetExceptionInfo(&exception);
while(1) {
image_info = CloneImageInfo((ImageInfo *) NULL);
(void) strcpy(image_info->filename, pic);
image = ReadImage(image_info, &exception);
if (exception.severity != UndefinedException)
CatchException(&exception);
resize_image = ResizeImage(image, 100, 200, LanczosFilter, 1.0, &exception);
DestroyImage(image);
if (resize_image == (Image *) NULL) {
CatchException(&exception);
} else {
resize_image->filename[MaxTextExtent-1] = '\0';
(void) strncpy(resize_image->filename, outfile, MaxTextExtent-1);
(void) WriteImage (image_info, resize_image);
}
}
DestroyImageInfo(image_info);
DestroyExceptionInfo(&exception);
DestroyMagick();
}
int main(int argc, char** argv) {
InitializeMagick(NULL);
boost::thread thrd1(&exec, "1.jpg");
thrd1.join();
return 0;
}
multi threads test case is like :
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <magick/api.h>
#include <boost/thread/thread.hpp>
using namespace std;
void exec(const char *pic) {
char outfile[MaxTextExtent];
(void) strncpy( outfile, "resize.jpg", MaxTextExtent-1 );
ExceptionInfo exception;
Image *image,
*resize_image;
ImageInfo *image_info;
GetExceptionInfo(&exception);
while(1) {
image_info = CloneImageInfo((ImageInfo *) NULL);
(void) strcpy(image_info->filename, pic);
image = ReadImage(image_info, &exception);
if (exception.severity != UndefinedException)
CatchException(&exception);
resize_image = ResizeImage(image, 100, 200, LanczosFilter, 1.0, &exception);
DestroyImage(image);
if (resize_image == (Image *) NULL) {
CatchException(&exception);
} else {
resize_image->filename[MaxTextExtent-1] = '\0';
(void) strncpy(resize_image->filename, outfile, MaxTextExtent-1);
(void) WriteImage (image_info, resize_image);
}
}
DestroyImageInfo(image_info);
DestroyExceptionInfo(&exception);
DestroyMagick();
}
int main(int argc, char** argv) {
InitializeMagick(NULL);
boost::thread thrd1(&exec, "1.jpg");
boost::thread thrd2(&exec, "2.jpg");
thrd1.join();
thrd2.join();
return 0;
}
use C++API test case is like:
#include <iostream>
#include <GraphicsMagick/Magick++.h>
#include <boost/thread/thread.hpp>
using namespace std;
using namespace Magick;
void exec(const char* pic) {
Image image;
while (1)
try {
int width = 100;
int height = 200;
image.read(pic);
char param_scale[64];
sprintf(param_scale,"%dx%d!",width,height);
image.scale(Magick::Geometry(param_scale));
image.write("self.jpg");
} catch(Exception &error_) {
cout << "Caught exception: " << error_.what() << endl;
}
}
int main(int argc, char **argv) {
InitializeMagick(*argv);
boost::thread thrd1(&exec, "1.jpg");
boost::thread thrd2(&exec, "2.jpg");
boost::thread thrd3(&exec, "3.jpg");
boost::thread thrd4(&exec, "4.jpg");
thrd1.join();
thrd2.join();
thrd3.join();
thrd4.join();
return 0;
}
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and
their applications. This 200-page book is written by three acclaimed
leaders in the field. The early access version is available now.
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may
_______________________________________________
Graphicsmagick-bugs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/graphicsmagick-bugs