Your skill will accomplish
what the force of many cannot
Threading Problemsby jerre_111 (Sexton)
|on Apr 23, 2013 at 07:53 UTC||Need Help??|
jerre_111 has asked for the
wisdom of the Perl Monks concerning the following question:
I'm facing some difficulties when I'm trying to implement a thread in my program. I don't know if I am thinking wrong about the usage of threads or if I'm facing some other problems?
First I'll try to explain the basic of the program which I'm trying to implement thread in.
I'm working in a Unix environment and I'm using Tk and Imager modules
The program basicly reads in an image and then draws it pixels by pixels on a canvas. Because it is taking some time to draw on the canvas if it is a big image, I want to add a progressbar while drawing the image.
Butt when I add the progress bar in the same sub routine as the drawing subroutine, it becomes even more slower. So I thought to use threads, by doing this I can work parallel on drawing on the progress bar at the same time. Right?
Because I never used threads before, I have read some articles about it at the perlthrtut pages in the hope of learning how threads works.
After reading this all, I managed to write this piece of code:
So basicly what this code does is first do some calculatios to get the percent of the total pixels (I need this to draw a realistic progress bar). Then I'm drawing the image pixel by pixel. While drawing the image, I want to start a thread that is updating the progress bar and doing the calculation for knowing the percent that is drawed already.
So that it the very basic of what I'm trying to do.
Butt, I'm not having any luck in creating a thread that does update the progress bar and so on.
I don't know what I'm doing wrong and where I'm doing it wrong. So could someone please help me in implementing the thread?1
Or maybe somebody has a better idea then using a thread?
Many Many thanks in advance