Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Sorry BrowserUK for being imprecise, It's not so much a matter of imprecision as omission; but no matter. To the problem. You haven't show what where $image in $image->setpixel() comes from. Its not GD (which has setPixel()) so I'm assuming it comes from Imager or Image::Magick or a similar package. The first question is: are the C/C++ libraries that underly that module thread-safe. To explain. If I run this short script that uses GD, it displays a 100x100 png with the left half red and the right half blue:
However, If I uncomment the two commented lines, thus the two rectangles are drawn to the image by different threads, I get this when I run it:
Ie. The libgd that underlies GD isn't threadsafe; and whilst the drawing to the image in the two threads executes without errors; when it comes to writing the image out to a file, a fatal error occurs. This isn't a limitation of perl's threading, but the underlying library. But you're using a different graphics libraryLet's explore if it makes any sense to write and image from multiple concurrent threads. Let's assume that one thread draws horizontal lines across the image in red, whilst another thread draws vertical bars down the image in blue. What should the resultant image look like? Like this? (You'll have to use your imagination here (#is red * is blue):
Or like this?:
Or some variation on this?:
Now you're probably thinking that as you're only using setPixel, and never writing to the same pixel twice, it doesn't matter what order things occur; but most graphics libraries retain a whole bunch of state between drawing calls -- eg. current clip region; current line pattern; current alpha setting; current .... -- and if two threads start modifying that internal state without using locking, then the internals of the image; and even the entire library can become corrupted. That's what happened with my GD example. Enough for one reply, more in the next. With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
In reply to Re^3: Threads From Hell #3: Missing Some Basic Prerequisites
by BrowserUk
|
|