Josef Reidinger write:
Ladislav Slezak write:
+ + # get the current progress + # returns a copy, use update_progress() for updating the progress + def get_progress(id) + @@mutex.synchronize do + ret = @@running[id] + ret.nil? ? nil : ret.dup
^^^ This return excepted value if you not make critical mistake ( because it return nil, if you unlock mutex on which you invoke synchronize method. So I recommend checking return value of synchronize to detect locking problem (but you must change inside block to not return nil in any case). so something like : ret = nil mret = @@mutex.synchronize do ret = @@running[id] ret = ret.dup unless ret.nil? "OK" done raise "Someone unlock mutex during executing synchronize" unless mret return ret
working in threads and locking need special care and study how it really work, otherwise some really ugly problem can raise.
Another fix my answer. It is not neccessary and it really works as you write it, because ensure has interesting behavior that it is not counted as last statement. from irb: begin "a" ensure "b" end => "a" so if synchronize call lock begin yield ensure unlock end it returns value from yield. So also another methods should be fixed just be removing 'return'. Josef -- Josef Reidinger YaST team maintainer of perl-Bootloader, YaST2-Repair, webyast (language,time,basesystem,ntp) -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org