multithreading - Ruby, simple "threading" example to update progress in console app -


i trying implement simple console app lots of long processes. during these processes want update progress.
cannot find simple example of how anywhere!
still "young" in terms of ruby knowledge , can seem find debates thread vs fibers vs green threads, etc.

i'm using ruby 1.9.2 if helps.

th = thread.new # here start new thread   thread.current['counter']=0   11.times |i| # loops , increases each time     thread.current['counter']=i     sleep 1   end   return nil end  while th['counter'].to_i < 10  # th long running thread , can access same variable inside thread here # keep in mind not safe way of accessing thread variables, reading status information # works fine though. read mutex better understanding.   puts "counter #{th['counter']}"    sleep 0.5 end  puts "long running process finished!" 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -