Created
January 4, 2011 07:22
-
-
Save pathsny/764495 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
files = [{:name => f1}, {:name => f2}, {:name => f3}] | |
index = 0 | |
scanner = Thread.new do | |
files.each do |f| | |
f[:sha1] = sha1(f[:name]) | |
index += 1 | |
end | |
end | |
updater = Thread.new do | |
local_index = 0 | |
while (local_index < files.size - 1) | |
if (local_index < index) | |
update_metadata(files[local_index]) | |
else | |
sleep(1) | |
end | |
end | |
end | |
scanner.join | |
updater.join | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
files = [{:name => f1}, {:name => f2}, {:name => f3}] | |
index = 0 | |
mutex = Mutex.new | |
scanner = Thread.new do | |
files.each do |f| | |
sha1 = sha1(f[:name]) | |
mutex.synchronize { | |
f[:sha1] = sha1 | |
index += 1 | |
} | |
end | |
end | |
updater = Thread.new do | |
local_index = 0 | |
while (local_index < files.size - 1) | |
if (local_index < mutex.synchronize {index} ) | |
update_metadata(files[local_index]) | |
else | |
sleep(1) | |
end | |
end | |
end | |
scanner.join | |
updater.join | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment