[pHash-support] threading related bugs

Evan Klinger eklinger at phash.org
Fri Jun 11 15:41:07 PDT 2010


Yes I do see the problem now. Thank you for pointing this out. We will
use your fix in the 0.9.1 release which will be out shortly.

Evan

On Fri, Jun 11, 2010 at 3:27 PM, Mostafa Razavi <hom.sepanta at gmail.com> wrote:
> I have not tested audio-related functions, so I'm sorry if my fix is not
> correct. I just knew that one parameter was missing and the code did not
> compile, so I thought buf would be the correct value to pass.
>
> I can elaborate about the second fix however. I noticed the problem, when I
> encountered segfaults when calling ph_dct_image_hashes with four input files
> and asking for four threads. After some digging in, it turned out that the
> code does not correctly slice the passed files for the threads. A simple
> test can show this. Suppose that we pass an array of four files and ask the
> function to use four threads. Just before entering the loop we have:
>
> rem = 0
> start = 0
> off =0
>
> after the first iteration:
>
> off = 1
> start = 1
> rem = -1
>
> in the subsequent iterations, off's value will not change (because rem is
> less than zero) so while the first thread calculates the cash for file 1,
> the other three will all work on file 2 and the third and four files will
> not be processed, hence the segfault when trying to retrieve the hashes. I
> think it's apparent that start needs to change for the function to slice its
> input correctly.
>
> I hope this clears things up. I should add that after changing "start = off"
> to "start += off" things started to work correctly.
>
> Cheers,
> Mostafa
>
> P.S.: I first sent this reply using my other mail account, and then I
> noticed my mistake and sent it again. Sorry about that. I think it would
> have been better if I had subscribed using this account since the other one
> is forwarded to this, and there's always the chance that I forget to change
> the sender.
>
>
> On Fri, Jun 11, 2010 at 11:46 PM, Evan Klinger <eklinger at phash.org> wrote:
>>
>> Mostafa,
>>
>> Thank you for submitting your patch. However, I believe the correct
>> fix in the multithreaded audio function is to pass NULL as the buf and
>> the readaudio() function will create the buffer for you and return it.
>> Can you explain your fix in the multithreaded image hash function? The
>> off variable is really the absolute starting position for the
>> subsequent thread and not an offset that should be added to start.
>> Please provide a test case where the function fails to set start
>> correctly.
>>
>> Thank you
>> Evan
>>
>> On Fri, Jun 11, 2010 at 11:53 AM, Mostafa Razavi <hom.sepanta at gmail.com>
>> wrote:
>> > Hi. I'm a new user of pHash and I just encountered two bugs in threading
>> > related codes. I think the patch is self-explanatory (only two lines
>> > have
>> > been changed). I made the patch against current source tarball (0.9.0).
>> >
>> > Cheers,
>> > Mostafa Razavi
>> >
>> >
>> > _______________________________________________
>> > pHash-support mailing list
>> > pHash-support at lists.phash.org
>> > http://lists.phash.org/listinfo.cgi/phash-support-phash.org
>> >
>> >
>
>
> _______________________________________________
> pHash-support mailing list
> pHash-support at lists.phash.org
> http://lists.phash.org/listinfo.cgi/phash-support-phash.org
>
>



More information about the pHash-support mailing list