Instead of enqueueing pixels, you enqueue an offset, and a length of 32 (and the thread will also need the width of the image).
With that data, each thread is able to calculate itself its tasked pixels.

Thus, if I have offset=0 the formula give calculates (x=0,y=0) to (x=8,y=0).
If I have offset=32 the formula give calculates (x=8,y=0) to (x=16,y=0).

Those are 8 pixels of 4 bytes each (RGBA).

you can avoid that thread-save problem with imagemagick.
You read an image and $blob=$original->ImageToBlob(); then manipulate all pixels in the blob, and BlobToImage() back.
See this imagemagick post.
And also this Permonk post: Re: reading in raw data into perl's ImageMagick

At least these primitives are ok with threads? (although not your eyes, you see I used seizure inducing red and green lines... sorry for that)

#! perl use warnings; use strict; use threads; use Image::Magick; my $image = Image::Magick->new( size => "600x600", ); $image->Read("xc:white"); for my $i (200..400){ async{ my $color = $i % 2 ? '#f00' : '#0f0'; $image->Draw( primitive => 'line', points => "$i,100 $i,500", stroke => $color, ); }->join; } $image->Set(magick=>'gif'); my $blob = $image->ImageToBlob(); open(FH,"> $0.gif")or die "$!\n"; print FH $blob; close FH;

perldoc threads


In reply to Re^3: Threads From Hell #3: Missing Some Basic Prerequisites by FreeBeerReekingMonk
in thread Threads From Hell #3: Missing Some Basic Prerequisites [Solved] by karlgoethebier

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.