westonplatter/phashion — pull request #26 by tenderlove (2013-12-09 02:32:25+00:00)
Title: unlock the GVL while calculating a hash

Hi,

I need to calculate the hashes for many images. This patch unlocks the GVL around hash calculation so that I can do hash calculations in parallel.

Here is a demo program:

```ruby
require 'phashion'
require 'find'
require 'thread'

queue = Queue.new

Find.find(ARGV[0]) do |f|
next if File.directory? f
queue << f if f =~ /jpg$/
end

threads = 4.times.map {
Thread.new {
while filename = queue.pop
Phashion.image_hash_for filename
end
}
}

4.times { queue << nil }
threads.each(&:join)
```

Here is CPU utilization before my patch:

![cpu utilization](https://dl.dropbox.com/s/p6aoyophvpa30v4/Activity_Monitor_All_Processes_20131208_183013.jpg)

Here is the CPU utilization after my patch is applied:

![cpu utilization2](https://dl.dropbox.com/s/cyrky5r8p06s460/Activity_Monitor_All_Processes_20131208_183152.jpg)